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 view this discussion on the web visit 
https://groups.google.com/d/msg/google-guice/-/Jnb7wizTq84J.
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