Comment #2 on issue 386 by sberlin: Child Injector JIT Singletons Not Eager
http://code.google.com/p/google-guice/issues/detail?id=386

Here's a full test that outlines four different scenarios.  Each of these  
pass when
the Injector is the parent injector, but in a child injector the last two  
fail.

---

package com.google.inject;

import junit.framework.TestCase;

public class ChildInjectorTest extends TestCase {

        @Override
        protected void setUp() throws Exception {
                AImpl.count = 0;
        }
        
        public void testExplicitEagerSingleton() {
                Guice.createInjector(Stage.PRODUCTION).createChildInjector(new  
AbstractModule() {
                        @Override
                        protected void configure() {
                                bind(AImpl.class);
                        }
                });
                assertEquals(1, AImpl.count);
        }
        
        public void testLinkedEagerSingleton() {
                Guice.createInjector(Stage.PRODUCTION).createChildInjector(new  
AbstractModule() {
                        @Override
                        protected void configure() {
                                bind(AInter.class).to(AImpl.class);
                        }
                });
                assertEquals(1, AImpl.count);
        }
        
        public void testImplicitEagerSingletonThroughSingleton() {
                Guice.createInjector(Stage.PRODUCTION).createChildInjector(new  
AbstractModule() {
                        @Override
                        protected void configure() {
                                bind(B.class).in(Scopes.SINGLETON);
                        }
                });
                assertEquals(1, AImpl.count);
        }
        
        public void testImplicitEagerSingletonThroughUnscoped() {
                Guice.createInjector(Stage.PRODUCTION).createChildInjector(new  
AbstractModule() {
                        @Override
                        protected void configure() {
                                bind(B.class);
                        }
                });
                assertEquals(1, AImpl.count);
        }
        
        @Singleton
        private static class AImpl implements AInter {
                static int count;
                AImpl() { count++; }
        }
        
        private static interface AInter {}
        
        private static class B { @Inject B(Provider<AImpl> a) {} }

}

--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" 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-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to