I have two named instances of type binding in my application:
bind(Foo.class).toProvider(FooProvider.class); bind(Foo.class).annotatedWith(Names.named("prime")).toProvider(FooPrimeProvider.class);
I have a class that would like to use one instance of each. For technical reasons, this class cannot insert instances directly; it must insert a provider into instances:
class Bar { @Inject static Provider<Foo> fooProvider; @Inject @Named("prime") static Provider<Foo> fooPrimeProvider;
The problem is that the FooPrime injection above does not inject an instance named "prime", it does introduce a provider named "prime", which, of course, is not what I want.
How can I say that Guice introduces a provider for the Foo instance named "prime"?
emmby source share