Skip to content

[Feat] Explicit definition override#2304

Merged
arnaudgiuliani merged 4 commits into4.2.0from
feat_explicit_override
Nov 5, 2025
Merged

[Feat] Explicit definition override#2304
arnaudgiuliani merged 4 commits into4.2.0from
feat_explicit_override

Conversation

@arnaudgiuliani
Copy link
Copy Markdown
Member

Add Explicit Override DSL (4.2.0-alpha2)

Summary

Adds fine-grained override control at the definition level, allowing specific definitions to override others even when global allowOverride(false) is enabled.

Changes

Core Feature:

  • New .override() DSL function for explicit per-definition override marking
  • Works with both fluent syntax (.override()) and withOptions { override() }
  • BeanDefinition.allowOverride: Boolean? property to track override flag
  • Updated InstanceRegistry to check definition-level override flag

API:

  startKoin {
      allowOverride(false)  // Strict mode
      modules(
          module { single<Service> { ProductionService() } },
          module { single<Service> { TestService() }.override() }  // ✅ Allowed
      )
  }

Use Cases:

  • Test configurations overriding production services
  • Feature flags conditionally overriding implementations
  • Plugin systems where specific plugins can override defaults

Documentation

  • Added comprehensive KDoc for all new functions
  • Updated docs: modules.md, definitions.md, dsl.md
  • Cross-references and examples included

Testing

  • ExplicitOverrideTest.kt with full coverage
  • Tests both .override() syntax and withOptions syntax
  • Tests binding scenarios

Version

Bumped to 4.2.0-alpha2

@arnaudgiuliani arnaudgiuliani added this to the 4.2.0 milestone Nov 5, 2025
@arnaudgiuliani arnaudgiuliani merged commit d1dbff7 into 4.2.0 Nov 5, 2025
3 of 4 checks passed
@arnaudgiuliani arnaudgiuliani deleted the feat_explicit_override branch November 5, 2025 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant