InsertKoinIO / koin

Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform
https://insert-koin.io
Apache License 2.0
9.08k stars 719 forks source link

Consider supporting nullable inject on compose #1789

Closed vulpeszerda closed 3 months ago

vulpeszerda commented 9 months ago

For using koin on compose, I used koinInject. However when composable function need to be injected nullable type, koinInject throw NoBeanDefFoundException.

It's because koinInject uses scope.get instead scope.getOrNull on below code.

@Composable
inline fun <reified T : Any> rememberKoinInject(
    qualifier: Qualifier? = null,
    scope: Scope = getKoinScope(),
    noinline parameters: ParametersDefinition? = null,
): T? {
    val st = rememberStableParametersDefinition(parameters)
    return remember(qualifier, scope) {
        scope.get(qualifier, st.parametersDefinition)
    }
}

This is necessary when providing optional module based on different flavor.

stale[bot] commented 4 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.