Tejas Gupta
09/19/2025, 6:13 AMModule.viewModel
injection for multiplatform. This seems to have been introduced in the 4.x.x release. (Please correct me if I’m wrong here)
While we do have an initiative to migrate to Koin 4.x.x, in the meantime we’re stuck with 3.x.x in our shared KMP project.
Our current idea is to go with the expect/actual approach to provide the ViewModels via Koin for both platforms. Here’s a rough outline of what we’re thinking - would love feedback on whether this approach makes sense, and if there are any pitfalls we should be aware of:
// commonMain
expect val platformModule: Module
val module: Module = module {
includes(platformModule)
}
// androidMain
actual val platformModule: Module = module {
viewModel {
MyViewModel()
}
}
// iOSMain
actual val platformModule: Module = module {
factory {
MyViewModel()
}
}
Any suggestions or alternative approaches are welcome! 🙏François
09/19/2025, 8:16 AMFrançois
09/19/2025, 8:16 AM