Hi,
Is it possible to get hold of annotations on the injection point inside a
provider ?
To make this more clear, I'd like to do the following,
Given a number of service classes:
class A { @Named("B") X x; ... }
class B { @Named("C") X x;... }
class C { ... }
...
And this module:
public class MyModule extends AbstractModule {
@Provides
@Named("A")
public X a(Injector inj) {
return createX(inj.getProvider(A.class)));
}
@Provides
@Named("B")
public X b(Injector inj) {
return createX(inj.getProvider(B.class)));
}
@Provides
@Named("C")
public X c(Injector inj) {
return createX(inj.getProvider(C.class)));
}
...
@Override
protected void configure() {
}
protected X createX(...) {
return ...;
}
}
but then without all the duplication of the providers. So ideally I'd like
to have this @Named() annotation as a parameter to the provider method.
So something like:
@Provides
public X createX(Y y, Injector inj) { // no idea what this Y would be
String name = getValueOfNamedAnnotation(y);
return createX(inj.getProvider(getImplementationClassFor(y))));
}
Is that possible?
thanks,
Bert
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/81f6f6ee-85af-4799-b70c-be02606672ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.