0
votes

I've started using Dagger 2 and faced strange issue. I have 4 modules, 3 of them in ApplicationComponent and the other one has different Scope (UsersScope).

Problem with injecting UsersInteractor into UsersPresenter

Error:[BlankFragment)] com.interactors.UsersInteractor cannot be provided without an @Inject constructor or from an @Provides-annotated method.

Here is my classes

@Singleton
@Component(modules = arrayOf(ApplicationModule::class, NetworkModule::class, DbModule::class))
interface ApplicationComponent {
    fun plusUsersComponent(usersModule: UsersModule): UsersComponent
}


@Module
class ApplicationModule(private val context: Context) {
@Provides
@Singleton
    fun provideContext(): Context = context
}

@Subcomponent(modules = arrayOf(UsersModule::class))
@UsersScope
interface UsersComponent {
    fun inject(blankFragment: BlankFragment)
}

@Module
class UsersModule {

@Provides
@UsersScope
fun provideUsersRepository(restService: RestService, dbService: DbService): IUsersRepository =
    UsersRepository(restService, dbService)

@Provides
@UsersScope
fun provideUsersInteractor(usersRepository: UsersRepository): IUsersInteractor =
    UsersInteractor(usersRepository)

@Provides
@UsersScope
fun provideUsersPresenter(usersInteractor: UsersInteractor): IUsersPresenter =
    UsersPresenter(usersInteractor)
}

@Scope
@Retention(AnnotationRetention.RUNTIME)
annotation class UsersScope
1

1 Answers

2
votes

There is no UsersInteractor known to Dagger since you only provide IUsersInteractor.

Switch your presenter provider method to use IUsersInteractor and it should work

fun provideUsersPresenter(usersInteractor: IUsersInteractor)