Skip to content

Applied the @DIDsl annotation to relevant builder interfaces and add specific convenience functions to [Arg]SetBinder#498

Merged
romainbsl merged 6 commits intomainfrom
feat/478/dsl
Nov 11, 2025
Merged

Applied the @DIDsl annotation to relevant builder interfaces and add specific convenience functions to [Arg]SetBinder#498
romainbsl merged 6 commits intomainfrom
feat/478/dsl

Conversation

@romainbsl
Copy link
Member

@romainbsl romainbsl commented Nov 11, 2025

closes #478

This pull request introduces convenience methods for adding bindings to sets in Kodein-DI, making the DSL more concise and user-friendly. It also applies the @DIDsl marker to enforce correct receiver scoping in the DSL, preventing accidental misuse of outer-scope methods inside set binding blocks. The documentation and tests are updated to reflect and verify these improvements.

Convenience methods for set bindings:

  • Added new methods to SetBinder and ArgSetBinder interfaces: addSingleton, addProvider, addInstance, addFactory, and addMultiton, allowing simpler and less nested syntax for common binding types.
  • Updated the implementation in DIBuilderImpl to support these new methods, ensuring they add the correct binding types to the set.

DSL correctness and safety:

  • Applied the @DIDsl annotation to relevant builder interfaces, including TypeBinder, DelegateBinder, ConstantBinder, SetBinder, and ArgSetBinder, to restrict method visibility and enforce correct DSL scoping.
  • Added a test to verify that only the intended methods are available in the SetBinder context, preventing accidental calls to outer DI.Builder methods.

Documentation updates:

  • Updated the multi-binding documentation to showcase the new convenience methods, providing clearer examples and explanations for users.

Testing:

  • Added comprehensive tests for the new convenience methods, including singleton, provider, instance, factory, and multiton bindings in sets, ensuring correct behavior and instance semantics.

Internal improvements:

  • Refactored internal code to use explicit this@DIBuilderImpl references for clarity and to avoid ambiguity in nested DSL contexts.

These changes make Kodein-DI's multi-binding DSL safer, more ergonomic, and easier to use for common scenarios.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request enhances Kodein-DI's multi-binding DSL by adding convenience methods for common binding types and applying the @DIDsl marker annotation to enforce proper receiver scoping. The changes make the DSL safer and more ergonomic for users.

  • Added convenience methods (addSingleton, addProvider, addInstance, addFactory, addMultiton) to reduce nesting when adding bindings to sets
  • Applied @DIDsl marker annotation to DSL interfaces to prevent accidental method calls from outer scopes
  • Updated documentation and added comprehensive tests to verify the new functionality

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
kodein-di/src/commonMain/kotlin/org/kodein/di/DI.kt Added @DIDsl annotations to builder interfaces and defined new convenience methods in SetBinder and ArgSetBinder interfaces
kodein-di/src/commonMain/kotlin/org/kodein/di/internal/DIBuilderImpl.kt Implemented convenience methods and added explicit scope qualifiers (this@DIBuilderImpl) to avoid ambiguity in nested contexts
kodein-di/src/commonTest/kotlin/org/kodein/di/Tests_18_MultiBindings.kt Added tests verifying DSL scoping enforcement and correct behavior of new convenience methods
doc/modules/core/pages/multi-binding.adoc Updated documentation to showcase new convenience methods with clear examples and explanations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@romainbsl romainbsl changed the title Mark DSL scoped functions to limit them to their receivers and add specific helper functions to [Arg]SetBinder Applied the @DIDsl annotation to relevant builder interfaces and add specific convenience functions to [Arg]SetBinder Nov 11, 2025
@romainbsl romainbsl merged commit f094518 into main Nov 11, 2025
2 checks passed
@romainbsl romainbsl deleted the feat/478/dsl branch November 11, 2025 21:36
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.

Too many receivers in scope for the DSL

1 participant

Comments