私はDagger 2の新機能です。私はAndroidプロジェクトでそれを実装しようとしています。 にはGoogleApiClient
が必要です。私はこのサービスでそれを注入するためにダガーを使用しています。ダガー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
が2つの@Singleton
スコープのコンポーネントに依存することはできませんが、私は両方必要な理解を私のサービスでそれらの両方が@Singleton
である必要があります。
同じことを行うには、より良い選択肢はありますか?
"私のLocationComponentは2つの@Singletonスコープコンポーネントに依存できないことを理解しています" - >これがなぜ不可能であるか説明できますか? –