没有AssistedInjection,我有以下
interface IA { ... }
class B implements IA {
B (String p)
}
class C implements IA {
C (String p)
}
interface IAFactory {
IA create(String p)
}
class BFactory implements IAFactory { ... }
class CFactory implements IAFactory { ... }
但是要使用AssistedInjection,我需要
class UberFactory {
B createB(@Assisted("stringB") String p)
C createC(@Assisted("stringC") String p)
}
以及B
和C
中的相应更改。
这有两个问题:
createB
或createC
UberFactory
切断了我的包结构,以实例化IA
在我看来,更直观的API将是:
install(new FactoryModuleBuilder()
.implement(IA.class, B.class)
.annotatedWith(BFactoryQualifier.class)
.build(IAFactory.class));
install(new FactoryModuleBuilder()
.implement(IA.class, C.class)
.annotatedWith(CFactoryQualifier.class)
.build(IAFactory.class));
这样我就可以简单地注释我注入我的应用程序代码的IAFactory
实例。
但据我所知,没有这样的API。所以,