2
假设我有一些像这样GWT延迟绑定和依赖注入
接口
Interface IsInterface {}
实现类
public ConcreteClassA implements IsInterface {
InjectorA a, InjectorB c, InjectorC c;
@Inject
ConcreteClassA(InjectorA a, InjectorB b, InjectorC c) {
this.a = a;
this.b = b;
.....
}
}
public ConcreteClassB implements IsInterface {
InjectorA a, InjectorB B, InjectorC C;
@Inject
ConcreteClassB(InjectorA a, InjectorB b, InjectorC c) {
this.a = a;
this.b = b;
.....
}
}
..和然后我决定使用GWT推迟的结合,所以我GWT module.gwt.xml
//Pseudo XML Configuration
if (type is IsInterface)
if toggle == A then use ConcreteClass A else use ConcreteClassB
现在,当我尝试运行这个。它不会工作,因为GWT期望我的具体类A和B具有默认的0构造函数。所以,我想在我的具体类
@Inject
InjectorA a;
@Inject
InjectorB b;
@Inject
InjectorC c;
ConcreteClassA() {
}
它绕过0构造错误以下,但它给了我NullPointerException异常时,我尝试使用,b或c。使它工作的一种方法是去除@Inject和使用GWT.create()像这样
InjectorA a, InjectorB b, InjectorC c;
ConcreteClassA() {
this.a = GWT.create(InjectorA.class);
.....
.....
}
这会工作,但如果我的InjectorA,InjectorB和InjectorC有没有0构造和严重依赖@Inject 。我不想通过所有的类来创建0构造函数,并用GWT.create()替换@inject。必须有更好的方法来做到这一点。我在这里错过了什么吗?
的可能重复的[杜松子酒内注射类生成通过延迟绑定](http://stackoverflow.com/questions/5490729/gin-injection-inside-class-generated的溶液逐推迟结合) – Vjeetje