0
我已經開始使用Dagger 2並面臨奇怪的問題。 我有4個模塊,其中3個在ApplicationComponent中,另一個有不同的Scope(UsersScope)。Kotlin Dagger 2無法提供交互者
問題與注射UsersInteractor
爲UsersPresenter
Error:[BlankFragment)] com.interactors.UsersInteractor cannot be provided without an @Inject constructor or from an @Provides-annotated method.
這裏是我的課
@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