@Inject 在 guice 模块中
@Inject in guice module
我们是否需要在模块 class 中使用 @Inject over provides___ 方法?
例如。
@Singleton
@Provides
@Inject
A provideA(ExampleClass1<B> example1, ExampleClass2 example2) {
return new A(example1, example2);
}
@Provides
@Singleton
@Inject
B provideB(A a) {
return new B(new C(a));
}
在这个例子中,我需要@Inject吗?
没有。 @Provides
方法不需要 @Inject
注释。 @Provides
方法的参数已经自动注入。
我们是否需要在模块 class 中使用 @Inject over provides___ 方法? 例如。
@Singleton
@Provides
@Inject
A provideA(ExampleClass1<B> example1, ExampleClass2 example2) {
return new A(example1, example2);
}
@Provides
@Singleton
@Inject
B provideB(A a) {
return new B(new C(a));
}
在这个例子中,我需要@Inject吗?
没有。 @Provides
方法不需要 @Inject
注释。 @Provides
方法的参数已经自动注入。