Comment #2 on issue 655 by [email protected]: Provider Factory and then
Inject what the Provider returns
http://code.google.com/p/google-guice/issues/detail?id=655
It looks like I can do something like this...
public class ConfigModule extends AbstractModule {
@Override
protected void configure() {
bind(PicasaConfig.class).toProvider(new
ConfigProvider<PicasaConfig>(PicasaConfig.class));
bind(FlickrConfig.class).toProvider(new
ConfigProvider<FlickrConfig>(FlickrConfig.class));
}
}
public class ConfigProvider<T> implements Provider<T> {
private final Class<T> type;
private volatile ClassLoader loader;
private volatile Environment environment;
public SettingsProvider(Class<T> type) {
this.type = type;
}
@Inject
void init(@Named("mv.config.cl") ClassLoader loader, @Named("my.env")
String environment) {
this.loader = loader;
this.environment = environment;
}
@Override
public T get() {
return DoSomeMagic.newInstance(loader, environment, type);
}
}
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" 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-dev?hl=en.