The big eye opener for me from http://groups.google.com/group/google-guice/browse_thread/thread/93dd8f0efc765ac8 is that:
bind(ReferenceFactory.class).to(EntityManagerImpl.class).in(TaskScoped.class); actually reads "ReferenceFactory is TaskScoped", as opposed to @TaskScoped EntityManagerImpl which reads "EntityManagerImpl is TaskScoped". Gili On Sep 24, 11:37 am, "Robbie Vanbrabant" <[EMAIL PROTECTED]> wrote: > Because your type annotated with @Singleton is the same as: > bind(PermanentRedirect.class).in(Singleton.class); > > Then bindings that have that type in the to(...) of their bindings will > reuse that instance because to(...) always refers to another binding > (implicit or explicit) > > See the discussion here for a longer > explanation:http://groups.google.com/group/google-guice/browse_thread/thread/93dd... > > Jesse, should't we add a FAQ item or something? This question seems to come > up all the time. > > Robbie > > On Wed, Sep 24, 2008 at 5:23 PM, Gili <[EMAIL PROTECTED]> wrote: > > > Hi, > > > Can someone please clarify why the following code yields different > > results? > > > 1) Scopes.SINGLETON approach: > > > ----------- > > binder.bind(Key.get(PermanentRedirect.class, > > > Names.named("RedirectMain"))).to(PermanentRedirect.class).in(Scopes.SINGLETON); > > binder.bind(Key.get(PermanentRedirect.class, > > > Names.named("RedirectWallpapers"))).to(PermanentRedirect.class).in(Scopes.SINGLETON); > > [...] > > Servlets.configure().filters().filterRegex("/main/gallery/ > > *").through(Key.get(PermanentRedirect.class, > > Names.named("RedirectGallery")), redirectGallery); > > [...] > > class PermanentRedirect not marked up using @Singleton > > ----------- > > > The main point here is that I've got multiple singletons bound against > > different Keys. > > > 2) @Singleton approach: > > > ----------- > > binder.bind(Key.get(PermanentRedirect.class, > > Names.named("RedirectMain"))).to(PermanentRedirect.class); > > binder.bind(Key.get(PermanentRedirect.class, > > Names.named("RedirectWallpapers"))).to(PermanentRedirect.class); > > [...] > > Servlets.configure().filters().filterRegex("/main/gallery/ > > *").through(Key.get(PermanentRedirect.class, > > Names.named("RedirectGallery")), redirectGallery); > > [...] > > class Permanent is marked up using @Singleton > > ----------- > > > I am expecting both approaches to yield the same result. In actuality, > > the @Singleton approach yields the same instance regardless of the > > Key... > > > Thank you, > > Gili --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-guice?hl=en -~----------~----~----~----~------~----~------~--~---
