In my project I have a configuration file that lists the concrete implementation of an interface.
How do I configure my Guice module so that I can get an instance of the concrete class from the Type whenever the interface is injected?
interface A{}
class AImpl implements A{ @Inject public A(.....)}
class B {
@Inject
public B(A a) {}
}
class MyModule extends AbstractModule {
...
@Provides
public A getA(@ConfiguredClass String classname) {
Class<A> aClass = (Class<A>) Class.forName(classname);
// ???
// this needs to be instantiated by Guice to fulfill AImpl's dependencies
return aClass.newInstance();
}
}
config:
class: my.package.AImpl