Commit 538004f
Fix koin#2402: explicit @KoinApplication modules override discovered @configuration
Runtime Koin is last-wins, so the order of module loading determines
which binding wins when multiple modules define the same type.
Before: explicit `@KoinApplication(modules = [...])` loaded first, then
auto-discovered `@Configuration` dependency modules. That meant a
dependency's default implementation silently overrode the app's custom
override, which is the opposite of typical intent ("the app customises
the libraries, not the other way round").
After: discovered modules load first, explicit list last. Within each
half, user-declared order is preserved — so
`@KoinApplication(modules = [A, B, C])` loads A, then B, then C, with
C winning over A and B as the declared order implies. Each entry's
`@Module(includes = [...])` chain stays grouped with that entry.
Dedupe is now against explicit, so a module re-listed in the explicit
`modules = [...]` keeps its explicit position rather than being merged
to the discovered half — user's explicit listing always wins
positionally.
Regression test (`testData/box/startkoin/explicit_modules_override_configuration.kt`):
a @configuration core module provides DefaultFeature, the app's
@KoinApplication(modules=[AppModule]) provides AppFeature as override,
runtime asserts `get<Feature>().name() == "app-override"`.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent cc9ee22 commit 538004f
5 files changed
Lines changed: 407 additions & 5 deletions
File tree
- koin-compiler-plugin
- src/org/koin/compiler/plugin/ir
- test-gen/org/jetbrains/kotlin/compiler/plugin/template/runners
- testData/box/startkoin
Lines changed: 18 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
289 | 302 | | |
290 | 303 | | |
291 | 304 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
462 | 462 | | |
463 | 463 | | |
464 | 464 | | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
465 | 471 | | |
466 | 472 | | |
467 | 473 | | |
| |||
0 commit comments