Perhaps I'm missing something, but I noticed binding annotations (including @nAmed) don't work on providers. For example:
public class TestModule extends AbstractModule {
@Override protected void configure() {}
@Provides
@Named("instance")
TestObject instance() {
System.out.println("instance");
return new TestObject();
}
@Provides
@Singleton
@Named("singleton")
TestObject singleton() {
System.out.println("singleton");
return new TestObject();
}
}
public classTestResource {
private final Provider<TestObject> singletonProvider;
private final Provider<TestObject> instanceProvider;
@Inject GuiceTestResource(
@Named("singleton") Provider<TestObject> singletonProvider,
@Named("instance") Provider<TestObject> instanceProvider) {
this.singletonProvider = singletonProvider;
this.instanceProvider = instanceProvider;
}
@GET void get() {
singletonProvider.get();
instanceProvider.get();
}
}
// Output:
// instance
// instance
Both providers use the default non-scoped object provider. However, if I make these different types and remove the binding annotations (e..g, TestObject1, TestObject2), then the scopes are honored it works.
Binding annotations should apply to Providers.
Known issue or am I missing something?
Perhaps I'm missing something, but I noticed binding annotations (including @nAmed) don't work on providers. For example:
Both providers use the default non-scoped object provider. However, if I make these different types and remove the binding annotations (e..g, TestObject1, TestObject2), then the scopes are honored it works.
Binding annotations should apply to Providers.
Known issue or am I missing something?