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.

Reply via email to