Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to register two singletons with Primary types of an interface. #2115

Open
MarcusDunn opened this issue Jan 14, 2025 · 1 comment
Open

Comments

@MarcusDunn
Copy link
Contributor

MarcusDunn commented Jan 14, 2025

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)
    }
@arnaudgiuliani
Copy link
Member

linked to this? #1811 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants