Skip to content

flatten modules order error #1998

Closed
@luozejiaqun

Description

@luozejiaqun

Describe the bug
The order of modules after flattened is wrong.

Koin module and version:
koin-core:4.0.0

Snippet:

    interface ComponentInterface1
    class Component1 : ComponentInterface1
    class Component2 : ComponentInterface1

    val m1 = module {
        single<Simple.ComponentInterface1> { Simple.Component1() }
    }
    val m2 = module {
        single<Simple.ComponentInterface1> { Simple.Component2() }
    }
    val m3 = module { includes(m1, m2) }
    val app = koinApplication {
        modules(m3)
    }

    val koin = app.koin
    val component = koin.get<Simple.ComponentInterface1>()
    assertTrue { component is Simple.Component2 } // this fails

Expected behavior
This is because when m3 gets flattened, we get modules in order m3, m2, m1, the expected order is m3, m1, m2.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions