Skip to content

Conversation

@arnaudgiuliani
Copy link
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.

2 participants