我遇到了数据类注入的问题。
数据类:
data class CoroutinesDispatcherProvider(
val main: CoroutineDispatcher,
val computation: CoroutineDispatcher,
val io: CoroutineDispatcher
)
而 viewModel 需要这个数据类:
class MyViewModel(private val dispatcherProvider: CoroutinesDispatcherProvider):ViewModel() {
}
最后模块是:
val appModule = module {
single { (main: CoroutineDispatcher, computation: CoroutineDispatcher, io: CoroutineDispatcher) ->
CoroutinesDispatcherProvider(
main,
computation,
io
)
}
viewModel { MyViewModel(get()) }
}
但得到错误:
Caused by: org.koin.error.BeanInstanceCreationException: Can't create definition for 'Factory [name='MyViewModel',class='com.example.myapplication.MyViewModel', binds~(androidx.lifecycle.ViewModel)]' due to error :
Can't create definition for 'Single [name='CoroutinesDispatcherProvider',class='com.example.myapplication.CoroutinesDispatcherProvider']' due to error :
Can't get parameter value #0 from org.koin.core.parameter.ParameterList@f87fb6
appModule 有什么问题?!