The reason overriding a binding in a child injector isn't supported is
because it can lead a developer towards writing code that can work in either
a parent & child injector, but have different behavior in each.  This can
lead to very surprising scenarios, because of just-in-time (JIT) bindings
and the way they interact with parent/child injectors.

Recycling an old reply to our internal guice list (about private modules,
but they're implemented with child injectors & have the same behavior) --
The design is such that just-in-time bindings are always created in the
parent injector first.  If it fails in the parent injector, then it's
created in the child injector (the private modules) .  In your scenario,
because one particular private module specifies the drink, the other private
modules will always have their drinks local to them, because the parent will
refuse to create a JIT binding if any of its children have a binding for
that key.

It's done this way because there's no way of knowing to know if the binding
should live in the parent or child, and choosing based on who asks for it
first (the parent or the child) is more a race condition than anything
else.  Consider if you really wanted drink to be a shared singleton such
that even the parent wanted to participate in the drinking but relied on the
JIT to do this.  If the child were to ask for the drink first and it was
created in the child injector, then the parent would never be able to drink
at all.

sam

On Mon, Oct 3, 2011 at 9:08 AM, [email protected] <[email protected]
> wrote:

> Sry, NOT WORKS for Providers
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-guice/-/j4ZGzu5KfIAJ.
>
> 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.
>

-- 
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.

Reply via email to