I'm pretty new to Dagger 2. I'm trying to implement it in my Android project.
I've a Service
which needs GoogleApiClient
. I'm using Dagger to inject it in this service.
@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
, and RepositoryModule
have methods marked @Singleton @Provides
When I build my project I get this error:
The locationServiceComponent depends on more than one scoped component: @Singleton NetComponent @Singleton RepositoryComponent
I understand my LocationComponent
cannot depend on two @Singleton
scoped components but I need both of them in my service and both need to be @Singleton
.
Is there any better alternative to do the same thing?