I am trying to be able to have this in my code
@Inject
private Map> providers;
I was trying but thi
Though Guice seems to be very good about using JSR-330 annotations interchangeably, it seems that Multibindings hides the Provider
type within a Map
and therefore may be expecting to inject a java.util.Map<java.lang.String, com.google.inject.Provider<...>>
instead. I haven't been able to reproduce your problem, but try that and see if it helps.
Side note: If you want to avoid changing it in code everywhere, you can hackishly bind a provider of Map<String, javax.inject.Provider<Foo>>
to something that takes in the multibinder-created Map<String, com.google.inject.Provider<Foo>>
. If I'm right and this is the problem, you can fix it one place rather than bouncing between javax.inject
and com.google.inject
everywhere.
If you want Map<String, Provider<Processor>>
at the injection point, the way to bind it is:
MapBinder<String, Processor> mapbinder = MapBinder.newMapBinder(binder, String.class, Processor.class);
mapbinder.addBinding("splineV1Beta").to(SplineProcessor.class);
mapbinder.addBinding("invertV1Beta").to(InvertProcessor.class);
You would use toProvider()
if you are supplying a custom provider, which you are not, i.e. you are merely trying to use the implicit underlying provider.