Hi all
According to the Guice wiki page
<https://github.com/google/guice/wiki/Scopes#choosing-a-scope>, unstopped
binding is preferred to Singleton for stateless objects.
First, I have a question about the definition of "stateless object".
1. Is an object depending on database connection considered stateless? (DAO)
2. Is an object depending on other stateless objects considered stateless?
3. Is definition of *stateless* equivalent to *immutable*?
I also have a few questions about the wiki page:
1. Singleton scope provides more information to developers. Developer can
assume it is thread-safe and inject them without using Provider most of the
time.
2. Creating an unscopped object can be expensive because of dependencies to
other unscopped objects.
3. It could be a bad idea to inject a Provider of unscopped objects, as the
memory and cpu cost of get() invocation is hard to predict.
4. Cyclic dependency of unscopped objects can only be resolved with
Provider, which could lead to behavior that is hard to predict.
e.g. *A* depends on *B*, *B* depends on *Provider<A>*, and some method
*f()* in *A* invokes *B* which invokes some method in *A*, then a new
instance of *A* and *B* will be created each time *f()* is called.
5. When someone injects an Request Scopped object into unscopped objects,
it is hard to tell if the reference could be leaked out of request scope.
It is more obvious that Request Scopped objects should be injected into
Singleton as Providers.
Best regards
Ran
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/db3f082a-9e21-4a6a-a6cd-f0eb35adb58b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.