Revision: 1483
Author: sberlin
Date: Sat Jan 29 12:42:22 2011
Log: fix issue 594 -- assistedinject does the wrong thing if assisted type
is scoped.
http://code.google.com/p/google-guice/source/detail?r=1483
Modified:
/trunk/extensions/assistedinject/src/com/google/inject/assistedinject/FactoryProvider2.java
/trunk/extensions/assistedinject/test/com/google/inject/assistedinject/FactoryModuleBuilderTest.java
=======================================
---
/trunk/extensions/assistedinject/src/com/google/inject/assistedinject/FactoryProvider2.java
Sun Oct 24 19:57:48 2010
+++
/trunk/extensions/assistedinject/src/com/google/inject/assistedinject/FactoryProvider2.java
Sat Jan 29 12:42:22 2011
@@ -29,6 +29,7 @@
import com.google.inject.Module;
import com.google.inject.Provider;
import com.google.inject.ProvisionException;
+import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.google.inject.internal.Annotations;
import com.google.inject.internal.BytecodeGen;
@@ -591,8 +592,9 @@
// but if it isn't, we'll end up throwing a fairly good error
// message for the user.
if(constructor != null) {
- binder.bind(assistedReturnType).toConstructor(
- constructor, (TypeLiteral)data.implementationType);
+ binder.bind(assistedReturnType)
+ .toConstructor(constructor,
(TypeLiteral)data.implementationType)
+ .in(Scopes.NO_SCOPE); // make sure we erase any scope on the
implementation type
}
}
};
=======================================
---
/trunk/extensions/assistedinject/test/com/google/inject/assistedinject/FactoryModuleBuilderTest.java
Sun Oct 24 19:57:48 2010
+++
/trunk/extensions/assistedinject/test/com/google/inject/assistedinject/FactoryModuleBuilderTest.java
Sat Jan 29 12:42:22 2011
@@ -36,6 +36,7 @@
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.Provides;
+import com.google.inject.Singleton;
import com.google.inject.Stage;
import com.google.inject.TypeLiteral;
import com.google.inject.internal.util.ImmutableSet;
@@ -458,4 +459,29 @@
public interface NotHidden {
Hidden create();
}
-}
+
+ public void testSingletonScopeOnAssistedClassIsIgnored() {
+ // production stage is important, because it will trigger eager
singleton creation
+ Injector injector = Guice.createInjector(Stage.PRODUCTION, new
AbstractModule() {
+ @Override
+ protected void configure() {
+ install(new FactoryModuleBuilder().build(SingletonFactory.class));
+ }
+ });
+
+ SingletonFactory factory =
injector.getInstance(SingletonFactory.class);
+ assertNotSame(factory.create("foo"), factory.create("bar"));
+ }
+
+ interface SingletonFactory {
+ AssistedSingleton create(String string);
+ }
+
+ @Singleton
+ static class AssistedSingleton {
+ @Inject
+ public AssistedSingleton(@Assisted String string) {
+ }
+ }
+
+}
--
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.