apr*_*dia 5 static android dependency-injection dagger-2
任何Dagger 2静态注射的例子.我已经尝试过这个: -
class A{
@Inject
static B b;
static {
getAppInstance().getComponent().inject(A.class);
}
static anyMethod(){
b.anotherMethod();
}
}
Run Code Online (Sandbox Code Playgroud)
public interface AppComponent{
void inject(Class<A> aClass);
}
Run Code Online (Sandbox Code Playgroud)
所以这是我建议的答案:-
class A{
private static B b = getAppInstance.getComponent().getB();
static anyMethod(){
b.anotherMethod();
}
}
Run Code Online (Sandbox Code Playgroud)
public interface AppComponent{
B getB();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2242 次 |
| 最近记录: |