While working on Android application using Dagger2 for dependency injects while defining Dagger component I'm getting this error
Error:(13, 1) error: This @Singleton component cannot depend on scoped components:
@Singleton com.eaxample.app.DaggerAndroid.networkhandler.WebserviceComponent
My code of component is here:
@Singleton
@Component(modules = {WebserviceModule.class}, dependencies = {ApplicationComponent.class})
public interface WebserviceComponent {
WebserviceHelper providesWebserviceHelper();
}
Code of componeent in which I'm getting error is:
@Singleton
@Component(modules = {RemoteDataModule.class}, dependencies = {WebserviceComponent.class})
public interface RemoteDataSourceComponent {
RemoteDataSource providesRemoteDataSource();
}
Why am I getting this error and how to resolve this?
While dmitriyzaitsev's answer explains why you get the error, here's how you can solve it:
Define your own scope (it will actually also behave like a Singleton scope). E.g. a file called RemoteDataScope.java
:
@Scope
@Retention(RetentionPolicy.RUNTIME)
public @interface RemoteDataScope {
}
Use the new scope, e.g. @RemoteDataScope
instead of @Singleton
in your RemoteDataSourceComponent
:
@RemoteDataScope
@Component(modules = {RemoteDataModule.class}, dependencies = {WebserviceComponent.class})
public interface RemoteDataSourceComponent {
RemoteDataSource providesRemoteDataSource();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With