我对匕首2很新。我试图在我的Android项目中实现它。 我有一个Service
需要GoogleApiClient
。我正在使用Dagger将其注入此服务中。匕首2:组件依赖于多个作用域组件
@FragmentScoped
@Component(dependencies = {NetComponent.class, RepositoryComponent.class})
public interface CustomServiceComponent {
void inject(CustomService customService);
}
@Singleton
@Component(modules = {AppModule.class, NetModule.class})
public interface NetComponent {
GoogleApiClient getGoogleApiClient();
}
@Singleton
@Component(modules = {AppModule.class, RepositoryModule.class})
public interface RepositoryComponent {
DatabaseService getDatabaseService();
}
AppModule
,NetModule
,并RepositoryModule
有方法标记@Singleton @Provides
当我建立我的项目,我得到这个错误:
The locationServiceComponent depends on more than one scoped component: @Singleton NetComponent @Singleton RepositoryComponent
我明白我的LocationComponent
不能取决于两个@Singleton
范围的组成部分,但我需要两个他们在我的服务和都需要是@Singleton
。
有没有更好的选择做同样的事情?
“我明白我的LocationComponent不能依赖于两个@Singleton作用域组件” - >你能解释为什么这是不可能的吗? –