Linked scopes order should be reversed / controllable
Describe the bug You can override a global single using a scope but you cannot do that with another scope linked to the first one doing this because of the order of scopes (root first).
ie : a global single bean, an override in the activity scope and used via the fragment scope.
To Reproduce
class ScopeTests {
companion object {
val koin = startKoin {
modules(
module {
single { MyBean("SINGLETON") }
scope(named("direct")) { scoped { MyBean("SCOPED") } }
scope(named("indirect")) { /* we will link this scope to "direct" */ }
}
)
}.koin
}
class MyBean(val name: String)
@Test
fun testSingleton() {
val bean = koin.get<MyBean>()
assertEquals("SINGLETON", bean.name)
}
@Test
fun testScopeDirectOverride() {
val scope = koin.getOrCreateScope("direct", named("direct"))
val bean = scope.get<MyBean>()
assertEquals("SCOPED", bean.name)
}
@Test
fun testScopeIndirectOverride() {
val direct = koin.getOrCreateScope("direct", named("direct"))
val indirect = koin.getOrCreateScope("indirect", named("indirect"))
indirect.linkTo(direct)
val bean = indirect.get<MyBean>()
assertEquals("SCOPED", bean.name) // fails because gets SINGLETON
}
}
Expected behavior At least root scope should be checked last but I think the checking order in Scope.findInOtherScopes should be reversed.
Koin project used and used version (please complete the following information): implementation "io.insert-koin:koin-android:3.2.0"
Parking your proposal in 4.0.0 for further new scope improvements 👍
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.
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.
Hi, @arnaudgiuliani any updates on this? will this be solved or will it remain in wont-fix status?