You may want to consider using
MapBinder<https://code.google.com/p/google-guice/wiki/Multibindings>,
and bind a map of <String, Communication>.  Then users inject the Map
(optionally as a Map<String, Provider<Communication>>) and call
.get(aString).

 sam


On Mon, Sep 23, 2013 at 5:05 PM, Rui Pacheco <[email protected]> wrote:

> (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.
>

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

Reply via email to