There are a lot of articles and discussions about the fact that Singleton scope 
is bad, but I don't really have the time to go dig them up. You should go back 
through the Guice mailing lists and check out some blogs around. I'm sure you 
can find a bunch of information on it.

However, I will throw out some thoughts I have on the topic of Singletons 
really quick:

Thread-safety
Request scoped objects (injecting the HttpServletRequest into a singletons is 
bad)
Connection scoped objects (injecting JDBC Connections into singletons is bad)
Can't use fields for data (or anything that isn't a singleton)
Introduces a lot of proxies or factories (to use EntityManager from a Singleton 
it must be a proxy or you must inject the EntityManagerFactory)
Transactions are more cumbersome (to wrap method-local variables inside 
transactions requires a LOT of magic. Think if you inject EntityManagerFactory 
and use it inside methods. How do you attach EntityManagers created in the 
methods to the Transaction scope that is running? You need proxies and magic)
Singleton's force everything below them to be Singletons. Refactoring and 
fixing issues with objects graphs downward is more difficult that upwards. If 
you make a root node a singleton, your entire graphs needs to be singletons. If 
you make your root nodes injection-scope, its children can be in any scope.

Overall, if a single class is a singleton it "infests" all of its dependencies, 
requiring all of them to be singletons (or factories/proxies) as well.

-- Brian

On Apr 8, 2013, at 9:35 AM, Jan Bernitt <[email protected]> wrote:

> If you seriously want help on this and not just bash on Silk than you
> should use Silk group https://groups.google.com/group/silk-di since this
> is purely Silk related. Of cause it is of importance how you defined the
> RootBundle class.
> 
> There actually is such a category. But no row for "overall feeling of
> reporting quality" since this obviously is subjective.
> Anyhow I have no problem to agree that guice has a very good reporting
> and silk is not there yet. This has to evolve through the usage.
> But it is good enough to see what the problem is - the below stack is
> informative enough to get an idea.
> 
> This singleton topic is funny. Where are the arguments ? Are you sure
> you don't confuse JVM singletons with container singletons ? Are you
> sure you do not talk about some kind of special use problems like for
> example GC related issues in application of very extreme characteristics
> when it comes to this ?
> 
> Jan
> 
> On 08.04.2013 16:57, Alen Vrečko wrote:
>> I tried to use it. It doesn't work. I get
>> 
>> Exception in thread "main" java.lang.RuntimeException:
>> java.lang.NoSuchMethodException: playground.Silk$RootBundle.<init>()
>>      at se.jbee.inject.bootstrap.Inspect.noArgsConstructor(Inspect.java:
>> 242)
>> ....
>> 
>> I have
>> 
>> class Foo
>> class Bar(Foo foo)
>> 
>> Injector injector = Bootstrap.injector(RootBundle.class);
>> Dependency<Bar> dependency = Dependency.dependency(Bar.class);
>> Bar instance = injector.resolve(dependency);
>> 
>> You should add another category: error reporting. You can put both
>> Silk and Spring in red and Guice in green. I tried to follow your
>> guide but I get the mentioned stack-trace.
>> 
>> I cannot help myself but to say the the usage of Singleton as the
>> default scope is archaic. In my book it qualifies for a QUADRUPLE
>> FACEPALM badge!!!
>> 
>> Cheers
>> Alen
>> 
>> On Apr 4, 9:07 am, Jan Bernitt <[email protected]> wrote:
>>> Hi,
>>> 
>>> I made a comparisonhttp://www.silkdi.com/help/comparison.htmlpage
>>> comparing my DI tool to other frameworks and guice is one of them.
>>> 
>>> Please let me know if I got something wrong (in the guice column) or you
>>> have additional or yet missing information I could add to make it more
>>> complete.
>>> Any other feedback is of cause also welcome.
>>> 
>>> Jan
> 
> -- 
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to