Guice: Child injector injecting root injector rather then itself

Created on 7 Jul 2014  路  3Comments  路  Source: google/guice

_From an.perez83 on April 15, 2010 06:54:44_

Hi everyone,

according to the JavaDoc of com.google.inject.Injector all injectors are supposed to have a binding
from Injector.class to themselves. Nevertheless, the child Injector seems to inject its root injector
rather then itself. I attached a short example code.

I guess that either the documentation or the implementation is faulty.

Cheers

Attachment: gist
   _child_injecting_parent.txt_

_Original issue: http://code.google.com/p/google-guice/issues/detail?id=472_

imported invalid

Most helpful comment

_From an.perez83 on April 15, 2010 04:04:34_

Alright, I figured out a workaround: one must bind the class into which the child injector is going to be
injected explicitly in he child injector's bindings. For my previous example, this would mean something like
this: bind(A.class);

Nevertheless, I consider the current behavior a bug.

All 3 comments

_From an.perez83 on April 15, 2010 04:04:34_

Alright, I figured out a workaround: one must bind the class into which the child injector is going to be
injected explicitly in he child injector's bindings. For my previous example, this would mean something like
this: bind(A.class);

Nevertheless, I consider the current behavior a bug.

_From sberlin on April 15, 2010 05:53:51_

This is because if the binding does not exist in the child injector's module, Guice
will create it as a "just in time" binding, and JIT bindings are created in the
parent modules (for a variety of reasons).

_From sberlin on April 25, 2010 15:17:14_

(No comment was entered for this change.)

Status: Invalid

Was this page helpful?
0 / 5 - 0 ratings