FlowFan
01/02/2025, 11:31 AMCaused by: org.koin.core.error.NoDefinitionFoundException: No definition found for type 'android.content.Context'. Check your Modules configuration and add missing type and/or qualifier!
Does it mean that if I want to provide Android context I can't use KoinApplication in commonMain?IgnacioCarrion
01/02/2025, 11:48 AM@Composable
fun App(koinAppDeclaration: KoinAppDeclaration? = null) {
KoinApplication(
application = {
koinAppDeclaration?.invoke(this)
modules(appModule)
}
) {
MaterialTheme {
MainScreen()
}
}
}
From all platforms you just call App function without the koinAppDeclaration and from Android you use it like this:
setContent {
App {
androidLogger(Level.DEBUG)
androidContext(this@MainActivity)
}
}
IgnacioCarrion
01/02/2025, 11:49 AMFlowFan
01/02/2025, 11:53 AMIgnacioCarrion
01/02/2025, 11:57 AMGiorgi
01/02/2025, 12:48 PMIgnacioCarrion
01/02/2025, 12:54 PM@OptIn(KoinInternalApi::class)
@Composable
fun KoinApplication(
application: KoinAppDeclaration,
content: @Composable () -> Unit
) {
val koin = rememberKoinApplication(koinApplication(application))
CompositionLocalProvider(
LocalKoinApplication provides koin,
LocalKoinScope provides koin.scopeRegistry.rootScope,
content = content
)
}
It uses remember and CompositionLocalProvider to provide the Koin instance. I'm pretty sure that with recompositions will not recreate the Koin instance but I'm not sure in the case of screen rotation.FlowFan
01/17/2025, 8:12 AM@Composable
@Preview
fun App() {
KoinMultiplatformApplication(
config = koinConfiguration {
defaultModule()
modules(
PlatformModule.module,
AppModule.module
)
}
) {
MainScreen()
}
}