我在刀柄中遇到 @ViewModelInject 问题

时间:2021-01-08 11:28:17

标签: android kotlin clean-architecture dagger-hilt

在刀柄中使用@viewmodelinject 时出现此错误

error: [Dagger/MissingBinding] com.example.domain.repositories.QuestionRepo cannot be provided without an @Provides-annotated method]

我的视图模型类

class MainViewModel @ViewModelInject constructor(

private val questionUseCaseImpl: QuestionUseCaseImpl,

): ViewModel(),LifecycleObserver {
val questionModel = MutableLiveData<QuestionModel>()
private val compositeDisposable = CompositeDisposable()

fun getData() {
    questionUseCaseImpl.execute()
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe({
            it?.let {
                questionModel.postValue(it)
            }
        },{

        }).let {
            compositeDisposable.add(it)
        }
}

override fun onCleared() {
    super.onCleared()
    compositeDisposable.clear()
}

域模块中我的存储库类

interface QuestionRepo{

    fun getQuestion(): Single<QuestionModel>
}

我在数据模块中的repositoryimpl类

    class QuestionRepoImpl @Inject constructor(
    private val questionMapper: dagger.Lazy<QuestionMapper>,
    private val service: Service
):QuestionRepo {
    override fun getQuestion(): Single<QuestionModel> {
        return service.getQuestion().map {
            questionMapper.get().toMapper(it)
        }

域模块中我的 usecaseimpl 类

class QuestionUseCaseImpl @Inject constructor(private val questionRepo: QuestionRepo):

QuestionUseCase<QuestionModel>{
override fun execute(): Single<QuestionModel> {
   return questionRepo.getQuestion()
}

0 个答案:

没有答案