ziv kesten
07/09/2024, 3:57 PMstopKoin
or close()
, and u try to init the SDK again, it will crash with org.koin.core.error.ClosedScopeException: Scope '_' is closed
I assume i need to use scopes here but i find it hard to understand from the docs, how i can incorporate scopes into my structure.
I have an object called KoinInstance
object KoinInstance {
val isGlobalKoinStarted: Boolean
get() = try {
GlobalContext.get() // Attempts to get the global Koin context
true // If it succeeds, Koin has been started
} catch (e: Exception) {
false // If it fails, Koin has not been started
}
val koinApp = if (isGlobalKoinStarted) {
koinApplication {
modules(myModules)
}
} else {
startKoin {
modules(myModules)
}
}
val koin = koinApp.koin
}
And i extend the KoinScopeComponent
like this
interface MyKoinComponent : KoinComponent {
// Override default Koin instance
override fun getKoin(): Koin = KoinInstance.koin
}
I initilize koin like this:
KoinInstance.koinApp.androidContext(context.applicationContext)
This works well until i try to call `close`/`unloadModules`/`stopKoin` to remove my classes and init the KoinApp again.
Any idea how i can incorporate scopes into this approach?arnaud.giuliani
07/11/2024, 7:30 AMziv kesten
07/11/2024, 7:35 AMarnaud.giuliani
07/11/2024, 8:04 AMwithoutclass
07/11/2024, 8:22 PM