I suspect there's another solution to the problem you're trying to solve here. Without knowing what that is, here are my guesses:
1) you don't actually need the parent injector, and you can pass an incomplete Module around until you need to create an injector, at which point you can combine that Module with the Module with your additional bindings in it 2) you use the parent injector, but want to use a runtime parameter to create objects of the same type in different contexts. In that case, AssistedInject <http://code.google.com/p/google-guice/wiki/AssistedInject>should do what you want. Keep in mind also that creating an injector can be expensive. Fred On Sat, Jul 28, 2012 at 10:07 AM, MarvinToll.com <[email protected]>wrote: > Interesting... I'm trying to do the same thing! > > On Jul 27, 7:57 am, Fedor Li <[email protected]> wrote: > > After searching the web for a solution to create an injector with a > module > > with missing bindings I didn't find any discussion about that. Is there a > > way to accomplish that? What I'm trying to do is to create a child > injector > > later on, which uses a module that provides the missing bindings and use > > that injector to create objects. Example: > > > > private static class DefaultModule extends AbstractModule > > { > > @Override > > protected void configure() > > { > > bind(IClassA.class).to(ClassA.class); > > /* > > * ClassA needs an implementation for IClassB. The binding for > > IClassB is not defined here. > > */ > > } > > > > } > > > > public final class ClassAFactory > > { > > private static final Injector injector = Guice.createInjector(new > > DefaultModule()); > > /* > > * Here the creation of the Injector fails, because the binding for > > IClassB is missing > > */ > > > > public static IClassA createClassA() > > { > > Injector functionalInjector = injector.createChildInjector(new > > AbstractModule() > > { > > @Override > > protected void configure() > > { > > bind(IClassB.class).to(ClassB.class); > > /* > > * Here I would satisfy the missing binding > > */ > > } > > }); > > > > return functionalInjector.getInstance(IClassA.class); > > } > > > > } > > > > Thanks for any help! > > -- > 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. > > -- 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.
