Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

di (feature): Add scalafmt-friendly DI bind syntaxes #3567

Merged
merged 2 commits into from
Jun 19, 2024
Merged

Conversation

xerial
Copy link
Member

@xerial xerial commented Jun 19, 2024

For preserving line breaks in Design bindings, we needed to add this scalafmt config:

optIn.breaksInsideChains = true

This configuration allows aligning bindings each line:

design
  .bind[X].toInstance
  .bind[Y].to[YImpl]

But this configuration can't be used with newlines.source configuration like:

newlines.source = unfold

A new DI binding syntax can be formatted well without using optIn.breaksInsideChains = true:

val design: Design =
  newDesign
    .bindSingleton[A]          // Bind A to a singleton instance of A
    .bindInstance[B](new B(1)) // Bind B to a concrete instance of B
    .bindImpl[A, AImpl]        // Bind A to AImpl
    .bindProvider{(d1: D1) => P(d1) } // Bind P using a provider function
    .bindProvider{(d1: D1, d2: D2) => P(d1, d2) } // Bind P using a provider function
    ...
    .bindProvider{(d1: D1, ..., d5: D5) => P(d1, ..., d5) } // Up to 5 arguments

@github-actions github-actions bot added doc Documentation task feature labels Jun 19, 2024
@xerial xerial enabled auto-merge (squash) June 19, 2024 16:46
@xerial xerial merged commit 6284e97 into main Jun 19, 2024
16 checks passed
@xerial xerial deleted the new-di-syntax branch June 19, 2024 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Documentation task feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant