Status: New
Owner: ----

New issue 373 by sberlin: Child Injector Linked Singletons Not Eager
http://code.google.com/p/google-guice/issues/detail?id=373

See the thread:
http://groups.google.com/group/google-guice/browse_thread/thread/32c683ff51c324d3
.

Linked singletons in a child injector from a parent injector using
Stage.PRODUCTION are not eagerly instantiated.

Example test (from the email thread)
---

    public void testChildEagerSingletons() {
         Injector parent = Guice.createInjector(Stage.PRODUCTION, new
AbstractModule() {
             @Override
             protected void configure() {
                 bind(S1.class).to(S1I.class);
             }
         });
         Injector child = parent.createChildInjector(new AbstractModule() {
             @Override
             protected void configure() {
                 bind(S2.class).to(S2I.class);
                 bind(S3I.class);
             }
         });

         assertTrue(S1I.created);
         assertSame(parent.getInstance(S1.class),  
child.getInstance(S1.class));

         assertTrue(S3I.created);
         assertTrue(S2I.created);
     }

     private static interface S1 {}
     @Singleton
     private static class S1I implements S1 {
         private static boolean created = false;
         S1I () { created = true; }
     }
     private static interface S2 {}
     @Singleton
     private static class S2I implements S2 {
         private static boolean created = false;
         S2I () { created = true; }
     }
     @Singleton
     private static class S3I {
         private static boolean created = false;
         S3I () { created = true; }
     }

---

This fails: assertTrue(S2I.created);

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