From c67fe78295612c01a0ab0565b89541c05a8c336f Mon Sep 17 00:00:00 2001 From: Arnaud Giuliani Date: Tue, 17 Dec 2024 10:07:08 +0100 Subject: [PATCH 1/3] bump kotlin version in example --- examples/gradle/versions.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gradle/versions.gradle b/examples/gradle/versions.gradle index 5ab3bdb37..1f3f49a18 100644 --- a/examples/gradle/versions.gradle +++ b/examples/gradle/versions.gradle @@ -1,6 +1,6 @@ ext { // Kotlin - kotlin_version = '2.0.20' + kotlin_version = '2.0.21' // Koin Versions koin_version = '4.0.1-Beta2' koin_android_version = koin_version From edc45befeaeb4ca701b9e34a58fb406443530005 Mon Sep 17 00:00:00 2001 From: Arnaud Giuliani Date: Tue, 17 Dec 2024 10:07:26 +0100 Subject: [PATCH 2/3] example use android debug log --- .../java/org/koin/sample/androidx/compose/MainApplication.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/sample-android-compose/src/main/java/org/koin/sample/androidx/compose/MainApplication.kt b/examples/sample-android-compose/src/main/java/org/koin/sample/androidx/compose/MainApplication.kt index f6a343875..dc25fd002 100644 --- a/examples/sample-android-compose/src/main/java/org/koin/sample/androidx/compose/MainApplication.kt +++ b/examples/sample-android-compose/src/main/java/org/koin/sample/androidx/compose/MainApplication.kt @@ -13,8 +13,8 @@ class MainApplication : Application() { super.onCreate() startKoin { -// androidLogger(Level.DEBUG) - printLogger(Level.DEBUG) + androidLogger(Level.DEBUG) +// printLogger(Level.DEBUG) androidContext(this@MainApplication) modules(appModule) } From ab5609117f6f449ab7a3ed5f4a28f3f0380f44cc Mon Sep 17 00:00:00 2001 From: Arnaud Giuliani Date: Tue, 17 Dec 2024 10:08:41 +0100 Subject: [PATCH 3/3] Fix to allow stable injection of parameters --- .../commonMain/kotlin/org/koin/compose/Inject.kt | 16 ++++++---------- .../org/koin/core/parameter/ParametersHolder.kt | 10 ++++++++++ .../kotlin/org/koin/core/ParametersHolderTest.kt | 11 +++++++++++ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/projects/compose/koin-compose/src/commonMain/kotlin/org/koin/compose/Inject.kt b/projects/compose/koin-compose/src/commonMain/kotlin/org/koin/compose/Inject.kt index f27428fa6..a5bf9ff48 100644 --- a/projects/compose/koin-compose/src/commonMain/kotlin/org/koin/compose/Inject.kt +++ b/projects/compose/koin-compose/src/commonMain/kotlin/org/koin/compose/Inject.kt @@ -16,11 +16,10 @@ package org.koin.compose import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberUpdatedState +import org.koin.core.annotation.KoinInternalApi import org.koin.core.parameter.ParametersDefinition -import org.koin.core.parameter.emptyParametersHolder +import org.koin.core.parameter.ParametersHolder import org.koin.core.qualifier.Qualifier import org.koin.core.scope.Scope @@ -33,18 +32,15 @@ import org.koin.core.scope.Scope * * @author Arnaud Giuliani */ +@OptIn(KoinInternalApi::class) @Composable inline fun koinInject( qualifier: Qualifier? = null, scope: Scope = currentKoinScope(), noinline parameters: ParametersDefinition? = null, ): T { - // This will always refer to the latest parameters - val currentParameters by rememberUpdatedState(parameters) - - return remember(qualifier, scope) { - scope.get(qualifier) { - currentParameters?.invoke() ?: emptyParametersHolder() - } + val params: ParametersHolder? = parameters?.invoke() + return remember(qualifier, scope, params) { + scope.getWithParameters(T::class, qualifier,params) } } diff --git a/projects/core/koin-core/src/commonMain/kotlin/org/koin/core/parameter/ParametersHolder.kt b/projects/core/koin-core/src/commonMain/kotlin/org/koin/core/parameter/ParametersHolder.kt index 2c7379eb4..94cdd49ee 100644 --- a/projects/core/koin-core/src/commonMain/kotlin/org/koin/core/parameter/ParametersHolder.kt +++ b/projects/core/koin-core/src/commonMain/kotlin/org/koin/core/parameter/ParametersHolder.kt @@ -139,6 +139,16 @@ open class ParametersHolder( } override fun toString(): String = "DefinitionParameters${_values.toList()}" + + override fun equals(other: Any?): Boolean { + if (other is ParametersHolder){ + return this.values == other.values + } else return false + } + + override fun hashCode(): Int { + return values.hashCode() + } } /** diff --git a/projects/core/koin-core/src/commonTest/kotlin/org/koin/core/ParametersHolderTest.kt b/projects/core/koin-core/src/commonTest/kotlin/org/koin/core/ParametersHolderTest.kt index daf2d9b0c..06aa53385 100644 --- a/projects/core/koin-core/src/commonTest/kotlin/org/koin/core/ParametersHolderTest.kt +++ b/projects/core/koin-core/src/commonTest/kotlin/org/koin/core/ParametersHolderTest.kt @@ -123,4 +123,15 @@ class ParametersHolderTest { val p = parametersOf(Simple.Component1()) assertNotNull(p.get()) } + + @Test + fun `equality check`() { + val p1 = parametersOf(1, 2, 3, 4) + val p2 = parametersOf(1, 2, 3, 4) + val p3 = parametersOf(1, 2, 3) + + assertEquals(p1, p2) + + assertNotEquals(p1,p3) + } }