Kodein integration¶
Success
To use the kodeinScreenModel
you should first import io.github.hristogochev:vortex-kodein
(see Setup).
Declare your ScreenModel
s using the bindProvider
bind.
val homeModule = DI.Module(name = "home") {
bindProvider { HomeScreenModel() }
}
Call kodeinScreenModel()
or kodeinNavigatorScreenModel()
to get a new instance.
class HomeScreen : Screen {
@Composable
override fun Content() {
val screenModel = kodeinScreenModel<HomeScreenModel>()
// ...
val navigator = LocalNavigator.currentOrThrow
val navigatorScreenModel = navigator.kodeinNavigatorScreenModel<HomeScreenModel>()
// ...
}
}
You can find source code for a working example here.