我對匕首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作用域組件」 - >你能解釋爲什麼這是不可能的嗎? –