Thanks a lot for your support. It works like a charm now. Finally, The easier the better !
I didn't know that you can define your module with Map<String, MyInterface> and then inject Map<String, Provider<MyInterface>> On 29 nov, 18:05, Bartosz Michalik <[email protected]> wrote: > On 11/29/2011 05:39 PM, Xanadu wrote: > > > public class MyModule extends AbstractModule { > > @Override > > protected void configure() { > > MapBinder<String, Provider<MyInterface>> providerMap = > > MapBinder.newMapBinder(binder(), new TypeLiteral<String>() {}, new > > TypeLiteral<Provider<MyInterface>>(){}); > > > providerMap.addBinding("myKey1").to(MyInterfaceImpl1Provider.class); > > > providerMap.addBinding("myKey2").to(MyInterfaceImpl2Provider.class); > > } > > } > > > Maybe my configuration is wrong... > > Try this > > public class MyModule extends AbstractModule { > @Override > protected void configure() { > MapBinder<String, MyInterface> binder = > MapBinder.newMapBinder(binder(), String.class, MyInterface.class); > binder.addBinding("X").toProvider(ProviderX.class); > binder.addBinding("Another") > .toProvider(AnotherProviderX.class); > } > > } > > public class Other { > @Inject public Other(Map<String, Provider<MyInterface> param) {} > > } > > and then you can use both Map<String, MyInterface> and Map<String, > Provider<MyInterface>> as parameters for other elements. The difference > is (as mentioned before) that in the first case object are created > before injection in the second case when the get() method of a provider > is called. > > Best regards, > Bartosz -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
