I'm not sure I understand all that you want to do.
You can create the map in a provider by injecting each different annotated
ItemService in the provider constructor, and adding them to the map that
you will return with the get() method.
Something like :
public class MyMapProvider implements Provider<Map<String, ItemService>> {
private final Map<String, ItemService> myMap;
@Inject
public MyMapProvider(@Named("datasource1") final ItemService datasource1,
@Named("datasource2") final ItemService datasource2,
@Named("datasource3") final ItemService datasource3,
@Named("datasource4") final ItemService datasource4) {
myMap = new HashMap<String, ItemService>();
myMap.put("datasource1", datasource1);
myMap.put("datasource2", datasource2);
myMap.put("datasource3", datasource3);
myMap.put("datasource4", datasource4);
}
@Override
public Map<String, ItemService> get() {
return myMap;
}
}
With that code, you will always return the same instance with the provider.
If that instance is modified, it will be visible for every class using it
(HashMap is not synchronized, so be careful with concurrent modification).
You can also write the provider to return a new instance at each call.
For the module manipulation, I never used it so I don't know how to do it
and if it will work.
Maybe adding a boolean to the ItemService so you know if the datasource is
active or not ?
You will need help from someone tht's better at guice.
Regards,
Mathieu
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-guice/-/KNNKAL2RAM4J.
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.