Hi,

Can anyone explain why this test fails?  Optional injection points seem to 
be getting ignored when they occur on a provider inside a private module. 
 The fact that this passes when you set optional=false leads me to believe 
that it might be a bug.  Using guice 3.0.

    public static class Foo { 
        public Bar bar;
        Foo(Bar bar) { this.bar = bar; }
    }
    
    static class Bar {  }
    
    static class FooProvider implements Provider<Foo> {
        @Inject(optional=false) public Bar bar;
        public Foo get() {
            return new Foo(bar);
        }
    }

    static class ChildInjectorInjector {
        public Injector injector;
        @Inject
        ChildInjectorInjector(Injector injector) {
            this.injector = injector;
        }
    }
    
    
    @Test
    public void test() throws Exception {
            Injector i = Guice.createInjector(new PrivateModule() {
                @Override protected void configure() {
                        bind(Bar.class);
                        bind(Foo.class).toProvider(FooProvider.class);
                        bind(ChildInjectorInjector.class);
                        expose(ChildInjectorInjector.class);
                    }
                });
        Injector ci = i.getInstance(ChildInjectorInjector.class).injector;
        Foo foo = ci.getInstance(Foo.class);
        assertTrue(foo.bar != null);
    }

-- 
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/-/-Dy8aIHd6R0J.
To post to this group, send email to google-guice@googlegroups.com.
To unsubscribe from this group, send email to 
google-guice+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to