hectoruiz
06/06/2024, 9:51 PMKoinContext(context = koinApplication {
modules(allModules)
}.koin) {
This is in the Platform.Android:
single<AppDatabase> { getDatabase(get()) }
This is in the navHost to obtain the instances of the view models:
val userListViewModel: UserListViewModel = koinViewModel()
And this is how I create the instances in a koin module:
private val viewModelModule = module {
viewModel {
UserListViewModel(get(), get(), get())
}
With all these config the following error appears:
Caused by: org.koin.core.error.NoBeanDefFoundException: No definition found for type 'android.content.Context'. Check your Modules configuration and add missing type and/or qualifier!Atul Gupta
06/06/2024, 9:54 PMstartKoin
method(this should happen in all the supported target)
actual class KoinInitializer(private val context: Context) {
actual fun init() {
startKoin {
androidContext(context)
androidLogger() // todo add build config check
modules(commonAppModules, platformModules)
}
}
}
Atul Gupta
06/06/2024, 9:55 PMKoinInitializer
hectoruiz
06/07/2024, 8:41 AMRichard Woollcott
06/07/2024, 9:09 AMclass MainApplication : Application() {
override fun onCreate() {
super.onCreate()
KoinInitializer(applicationContext).init(androidModule)
}
}
actual class KoinInitializer(
private val context: Context
) {
actual fun init(platformSpecific: Module): KoinApplication = startKoin {
androidContext(context)
androidLogger()
modules(appModule() + platformSpecific)
}
}
Where we pass the Context to Koin, there is a working app at https://github.com/Appmilla/KMPJetpackDemo, which uses DataStore, it might helpRichard Woollcott
06/07/2024, 9:12 AMhectoruiz
06/07/2024, 10:13 AM