Unable to register two singletons with Primary types of an interface.
Describe the bug Missing definitions when underyling class is unknown by koin. I belive this is due to the name of the definition overriding another.
To Reproduce Steps to reproduce the behavior:
This test fails.
class TestGetAllWithLogicInSingleBlock {
interface Foo
class A : Foo
class B : Foo
@Test
fun `check get all with logic in single block`() {
val app = koinApplication {
modules(module {
single {
if (Random.nextBoolean()) {
A()
} else {
B()
}
} bind Foo::class
single {
if (Random.nextBoolean()) {
A()
} else {
B()
}
} bind Foo::class
})
}
app.koin.getAll<Foo>().shouldHaveSize(2)
}
}
Expected behavior
I would expect two instances of Foo to be available in getAll<Foo>()
Koin module and version:
koin-core:4.0.1
Additional information adding qualifiers fixes the issue:
This test passes (as expected)
@Test
fun `check get all with logic in single block`() {
val app = koinApplication {
modules(module {
single(qualifier("1")) {
if (Random.nextBoolean()) {
A()
} else {
B()
}
} bind Foo::class
single(qualifier("2")) {
if (Random.nextBoolean()) {
A()
} else {
B()
}
} bind Foo::class
})
}
app.koin.getAll<Foo>().shouldHaveSize(2)
}
linked to this? https://github.com/InsertKoinIO/koin/issues/1811#issuecomment-2588619709
I believe it's unrelated.
For this one, the issue I think is that these both generate an index of com.example.Foo::_ROOT_, which is why the qualifier fixes it. I'm not sure exactly what a fix would be without breaking the working as intended overriding behavior.
Problem in your case, you can override the current same index A :: Foo if you take both A on your script