我有这个组件:
@Singleton
@Component(modules = OauthModule.class)
public interface OauthComponent {
void inject(LoginActivity a);
}
和模块:
@Module
public class OauthModule {
@Provides
@Singleton
Oauth2Service provideOauth2Service() {
return new Oauth2StaticService();
}
}
还有另一个组件:
@Singleton
@Component(modules = LoggedUserModule.class)
public interface LoggedUserComponent {
void inject(LoginActivity a);
}
我遇到了这个错误:
Error:(15, 10) error: Oauth2Service不能没有@Provides-或@Produces-注释的方法提供。
如果我将LoggedUserComponent
的inject方法参数更改为另一个Activity
,比如像这样的AnotherActivity
:
@Singleton
@Component(modules = LoggedUserModule.class)
public interface LoggedUserComponent {
void inject(AnotherActivity a);
}
编译没问题。为什么?我不能有两个具有相同注入签名的组件吗?
我正在努力理解 Dagger
的工作原理,非常感谢您的帮助。