InsertKoinIO / koin

Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform
https://insert-koin.io
Apache License 2.0
8.77k stars 695 forks source link

fix(flatten): use `LinkedHashSet` instead of `HashSet` #1841

Closed hoc081098 closed 2 months ago

hoc081098 commented 2 months ago

to maintain the insertion order

arnaudgiuliani commented 2 months ago

still get error, but order is maintained in the reverse order I see 🤔

@Test
    fun `allow overrides by type`() {
        val app = koinApplication {
            modules(
                module {
                    single<Simple.ComponentInterface1> { Simple.Component2() }
                },
                module {
                    single<Simple.ComponentInterface1> { Simple.Component1() }
                },
            )
        }

        app.assertDefinitionsCount(1)
        assertTrue(app.koin.get<Simple.ComponentInterface1>() is Simple.Component1)
    }

Good thing is that order seems stable

image

arnaudgiuliani commented 2 months ago

Could test that with this test too:

@Test
    fun test_flatten_list() {

        (1..100).all { i ->
            val modules = listOf(module { },module { },module { },module { },module { },module { },module { },module { },module { },module { })
            val flatten = flatten(modules)
            flatten.reversed() == modules
        }
    }
hoc081098 commented 2 months ago

@arnaudgiuliani just updated

-ArrayDeque(modules)
+ArrayDeque(modules.asReversed())
arnaudgiuliani commented 2 months ago

Sounds good 🎉. Need to check the fails on test examples 🤔

arnaudgiuliani commented 2 months ago

Seen the problem. It's not from your side 👍 Will fix it