(Also posted on stackoverflow <http://stackoverflow.com/q/18968410/2808692>)
I have several classes implementing interface Provider<Communication> and
I'm using Guice with a @Named annotation to bind them as required, e.g.:
@Singletonpublic class Verizon implements Provider<Call> {
...}
@Singletonpublic class TMobile implements Provider<Call> {
...}
bind (new TypeLiteral<Provider<Call>>() {}).annotatedWith(
Names.named("Verizon")).to(Verizon.class);
bind (new TypeLiteral<Provider<Call>>() {}).annotatedWith(
Names.named("TMobile")).to(TMobile.class);
Is there a clean way to implement a factory that takes the name as a
parameter, e.g.:
public static <C extends Communication> Provider<C> getCallProvider(C
communication) {
String providerName = communication.getProviderName();
return [Guice's matching object for type Provider<?> and @Named =
providerName];}
--
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 http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.