Let me ask this another way. The following test case succeeds:

public class ATest {

        static class A {
                final B b;
                A(B b) { this.b = b; }
        }

        static class B {
        }

        static class AProvider implements Provider<A> {
                final B b;
                @Inject AProvider(B b) { this.b = b; }
                public A get() { return new A(b); }
        }

        @Test
        public void testProviderListener() {
                final AtomicInteger counter = new AtomicInteger();
                Injector injector = Guice.createInjector(new AbstractModule() {
                        @Override
                        protected void configure() {
                                bind(A.class).toProvider(AProvider.class);
                                bindListener(
                                                Matchers.only(new 
TypeLiteral<AProvider>(){}),
                                                new TypeListener() {
                                                        public <I> void 
hear(TypeLiteral<I> type,
                                                                        
TypeEncounter<I> encounter) {
                                                                
counter.incrementAndGet();
                                                        }
                                                });
                        }
                });
                injector.getProvider(A.class);
                Assert.assertEquals(1, counter.get());
        }
}

But if I replace the matcher with: Matchers.only(new
TypeLiteral<Provider<A>>(){}) it doesn't.

I'm guessing this is because of type erasure. Am I doing something
wrong/ is there another way to do this?

Thanks,

Eelco

p.s.
>                bindListener(Matchers.only(new TypeLiteral<SessionFactory>() {
I meant new TypeLiteral<Provider<SessionFactory>>(){}

-- 
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