I have two named instances of a type bound 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 inject the instances directly, it must inject a provider to the instances:
class Bar {
@Inject static Provider<Foo> fooProvider;
@Inject @Named("prime") static Provider<Foo> fooPrimeProvider; // WRONG!
}
The problem is that the FooPrime injection above is not injecting an instance named "prime", it's injecting a Provider named "prime", which of course is not what I want.
How do I tell Guice to inject a provider for the Foo instance named "prime"?