I have a class that requires an Injector to do some work (it needs to
construct some objects on the fly and then injectMembers for them).

class DoSomething {
    @Inject protected Injector injector;

    public void doIt() {
        ...
        injector.injectMembers(stuff);
        ...
    }
}


In my application, I have two levels of injector.  I have a master
injector, created using Guice.createInjector(), and I have a few child
injectors, created by calling master.createChildInjector().  I've
verified that DoSomething was created using a binding in one of the
child injectors.

The weird thing is that if I inspect DoSomething.injector, I find that
it is the MASTER injector, not the CHILD injector.  I would have
expected the Injector to be the child injector since it was the child
that instantiated DoSomething.

This seems to be causing me problems like the following:

E/AndroidRuntime( 1515): com.google.inject.ConfigurationException:
Guice configuration errors:
E/AndroidRuntime( 1515):
E/AndroidRuntime( 1515): 1) A binding to
com.google.inject.Provider<android.app.Activity> already exists on a
child injector.
E/AndroidRuntime( 1515):   while locating
com.google.inject.Provider<android.app.Activity>
E/AndroidRuntime( 1515):     for field at
com.XXX.http.BaseHttpGet.activityProvider(Unknown Source)
E/AndroidRuntime( 1515):   while locating com.XXX.model.ImageUtils
$GetImage
E/AndroidRuntime( 1515):
E/AndroidRuntime( 1515): 2) A binding to com.XXX.http.Http already
exists on a child injector.
E/AndroidRuntime( 1515):   while locating com.XXX.http.Http
E/AndroidRuntime( 1515):     for field at com.XXX.http.BaseHttpGet.http
(Unknown Source)
E/AndroidRuntime( 1515):   while locating com.XXX.model.ImageUtils
$GetImage
E/AndroidRuntime( 1515):

My interpretation of that error is that when I call
injector.injectMembers(), the master injector attempts to generate a
few bindings that it can't find, but errors out because those bindings
already exist in the child injector.

Is there a way I can tell Guice to inject the "correct" Injector
instead of always the root injector?  Or alternately, is there a way I
can get the correct injector manually somehow?

Cheers,
Mike
--~--~---------~--~----~------------~-------~--~----~
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