You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Very similar to: #1176
Scopes created by KoinScopeComponent are sharing instance cache.
Good real-life example is RequestScope form koin-ktor. If somewhere mid pipeline we fail to register one of instances via scope.declare and fail, instance from previously successful requests will still be returned by Koin when requested further down the pipeline.
To Reproduce
Isolated case:
class MyScopeComponent(private val _koin: Koin) : KoinScopeComponent {
override fun getKoin(): Koin = _koin
override val scope: Scope = createScope()
}
fun main() {
val koin = koinApplication { printLogger(Level.DEBUG) }.koin
val scopeComponent = MyScopeComponent(koin)
val scope = scopeComponent.scope
scope.declare("hello")
require("hello" == scope.get<String>())
scope.close()
val scopeComponent2 = MyScopeComponent(koin)
val scope2 = scopeComponent2.scope
require(scope2.getOrNull<String>() == null)
}
Expected behavior
Both require expressions in "To reproduce" should pass
Koin module and version: koin-core:3.5.5
Snippet or Sample project to help reproduce
See "To reproduce"
The text was updated successfully, but these errors were encountered:
The declare function takes your instance as a new definition for this kind of scope. It will return the value as the instance of the factory. This is why in 2 different scope's instances, you get the result again.
I changed the implementation of declared instances in scope: #2082
Describe the bug
Very similar to: #1176
Scopes created by
KoinScopeComponent
are sharing instance cache.Good real-life example is
RequestScope
formkoin-ktor
. If somewhere mid pipeline we fail to register one of instances viascope.declare
and fail, instance from previously successful requests will still be returned by Koin when requested further down the pipeline.To Reproduce
Isolated case:
Expected behavior
Both
require
expressions in "To reproduce" should passKoin module and version:
koin-core:3.5.5
Snippet or Sample project to help reproduce
See "To reproduce"
The text was updated successfully, but these errors were encountered: