Dears,
In the scope of a game, I would like to generate random areas on the fly, based upon some parameters and a specific type. The parameters depend on the area that I want to build. The thing is that there are several types of providers (or generators). One per string identifier. For the moment, I have the following in my module: for (...) { String areaType = ...; Properties areaParameters = ...; String areaId = ...; Provider<Area> provider; if ("type1".equals(areaType)) { provider = new Type1AreaProvider(areaParameters); } else if ("type2".equals(areaType)) { provider = new Type2AreaProvider(areaParameters); } else if ... // Dozen of types Areas.bindArea(binder(), areaId).toProvider(provider); } I would like to refactor this in a named FactoryProvider of Provider so my code looks like this (using an interface AreaProviderFactory): // Areas.bind... uses the ProviderFactory internally. Areas.bindAreaProviderFactory(binder(), "type1", Type1AreaProvider.class); Areas.bindAreaProviderFactory(binder(), "type2", Type2AreaProvider.class); ... // Somehow retrieve a fully injected areaProviderFactories Xxxx areaProviderFactories = ...; for (...) { String areaType = ...; Properties areaParameters = ...; String areaId = ...; Provider<Area> provider = areaProviderFactories.get(areaType).create(areaParameters); Areas.bindArea(binder(), areaId).toProvider(provider); } The questions are: * How to get the areaProviderFactories (being a map, an injector or whatever) generated already inside my Module (or using just a Binder if I want to get it in a static helper method)? I've thought about a method-private class with "@Inject Map<String,AreaProviderFactory> factories;" and a call to requestInjection() on an instance of that class but I find this ugly; if I want to use the static helper, that means I have to inject this for every call, which I would rather avoid. * What is the best to create/get these factories in this scope: using a MapBinder or the Injector+Named annotation? I'm still using Guice 2.0 for this project. Is there any way Guice 3.0 helps me better? Thank you very much, Olivier -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to google-gu...@googlegroups.com. To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.