我正试着在我的数据源类中注入一个带koin的contentProvider,但是我找不到任何方法可以做到这一点。
这是我的dataSource
class MyDataSource(private val application: Application, private val contentProvider: ContentResolver) : MyRepository {...}和我的koin模块
single<MyRepository> {
MyDataSource(get(), get())
}我得到了这个错误:
原因: org.koin.core.error.NoBeanDefFoundException:找不到'android.content.ContentResolver‘的定义。检查您的模块定义。
发布于 2020-07-27 18:28:19
告诉Koin如何获得ContentResolver。假设您在自定义Application (比方说MyApplication)类中初始化了模块:
private val module = module {
single { this@MyApplication.contentResolver } // tell Koin this is your ContentResolver
single<MyRepository> {
MyDataSource(get(), get()) // now Koin knows how to get the content resolver here
}
}https://stackoverflow.com/questions/63111727
复制相似问题