Skip to content

Instantly share code, notes, and snippets.

@xajik
Created February 25, 2021 15:38
Show Gist options
  • Save xajik/e53c893fe4eb56fe961785eb7fdebb61 to your computer and use it in GitHub Desktop.
Save xajik/e53c893fe4eb56fe961785eb7fdebb61 to your computer and use it in GitHub Desktop.
Kodein DI examp;e for Kotlin/Native
private val databaseModule = DI.Module("database") {
bind<SqlDriver>() with singleton {
DatabaseFactory.createEngine(instance(), instance(), isDebug)
}
//...
}
private val viewModelModule = DI.Module("viewModel") {
bind<LoginViewModel>() with provider {
LoginViewModel(
instance(), instance(), instance(), instance(), instance(), instance(), instance()
)
}
//...
}
private val kodein = DI {
import(databaseModule)
import(viewModelModule)
//...
}
//Use provider to get access to DI
val provider = Provider(kodein)
//DIAware component
class Provider(override val di: DI) : DIAware
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment