Ok, it's clear for me, Jesse. Thanks for so fast response. But, as to me it's very mind-boggling...
> Just-in-time bindings created for child injectors will be created in > an ancestor injector whenever possible. Whenever possible? Why in my example ManagerImpl was created in child injector (two different singletons), but BuilderImpl was created in ancestor (one singleton for both trees)? Both is just-in-time bindings, isn't it? Aleksey. On 22 май, 21:15, "[email protected]" <[email protected]> wrote: > Short version: add the following statement to your private module and > you'll get your desired behaviour. > bind(ManagerImpl.class); > bind(BuilderImpl.class); > > Longer version: > When you say: bind(Foo.class).to(FooImpl.class), you're creating an > explicit binding for Foo that links to a just-in-time binding for > FooImpl. From the Injector.createChildInjector() javadoc, > Just-in-time bindings created for child injectors will be created in > an ancestor injector whenever possible. This allows for scoped > instances to be shared between injectors. Use explicit bindings to > prevent bindings from being shared with the parent injector. > Guice prefers to share bindings whenever it has the opportunity. If > it's creating a Just-in-time binding, it'll do so in the top-level > injector wherever possible. > > I admit that this is somewhat mindboggling. Of the two possible > behaviours, we went with this one because we prefer to err on the side > of singletons really being singletons. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
