Created
February 25, 2021 15:38
-
-
Save xajik/e53c893fe4eb56fe961785eb7fdebb61 to your computer and use it in GitHub Desktop.
Kodein DI examp;e for Kotlin/Native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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