【发布时间】:2016-01-20 15:14:48
【问题描述】:
Dagger 2 静态注入的任何示例。我已经尝试过了:-
class A{
@Inject
static B b;
static {
getAppInstance().getComponent().inject(A.class);
}
static anyMethod(){
b.anotherMethod();
}
}
public interface AppComponent{
void inject(Class<A> aClass);
}
【问题讨论】:
-
为什么需要它是静态的?单例提供者应该可以满足您的需求。
-
@davehenry 您可能希望它是静态的,以便可以与静态方法一起使用。
标签: android dependency-injection static dagger-2