Author: limpbizkit
Date: Thu Oct 16 09:15:48 2008
New Revision: 640

Modified:
     
trunk/extensions/privatemodules/src/com/google/inject/privatemodules/PrivateModule.java
    trunk/src/com/google/inject/Initializer.java

Log:
Incorporating improvements suggested by Daniel Martin - making  
PrivateModule's Provider<Ready> work in two steps rather than as an eager  
singleton.

Modified:  
trunk/extensions/privatemodules/src/com/google/inject/privatemodules/PrivateModule.java
==============================================================================
---  
trunk/extensions/privatemodules/src/com/google/inject/privatemodules/PrivateModule.java
  
(original)
+++  
trunk/extensions/privatemodules/src/com/google/inject/privatemodules/PrivateModule.java
  
Thu Oct 16 09:15:48 2008
@@ -172,21 +172,17 @@
        }

        // create the private injector while the public injector is  
injecting its members. This is
-      // necessary so the providers from getProvider() will work.
+      // necessary so the providers from getProvider() will work. We use  
provider injection as our
+      // hook. Guice promises that initialize() will be called before a  
Ready is returned.
        publicBinder.bind(readyKey).toProvider(new Provider<Ready>() {
-        @Inject Injector publicInjector;
-        private Ready result;
-        public Ready get() {
-          // Build the child injector once. This method is called multiple  
times when we have
-          // creation-time dependencies from private on public and from  
public to private.
-          if (result == null) {
-            result = new Ready();
-            publicInjector.createChildInjector(privateModule);
-          }
+        @Inject void initialize(Injector publicInjector) {
+          publicInjector.createChildInjector(privateModule);
+        }

-          return result;
+        public Ready get() {
+          return new Ready();
          }
-      }).asEagerSingleton();
+      });

      } finally {
        readyProvider = null;

Modified: trunk/src/com/google/inject/Initializer.java
==============================================================================
--- trunk/src/com/google/inject/Initializer.java        (original)
+++ trunk/src/com/google/inject/Initializer.java        Thu Oct 16 09:15:48 2008
@@ -139,7 +139,7 @@
          }
        }

-      // toInject needs injection, do it right away
+      // toInject needs injection, do it right away. we only do this once,  
even if it fails
        if (pendingInjection.remove(instance) != null) {
          injector.injectMembersOrThrow(errors.withSource(source), instance);
        }

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