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

Provide a way to delegate to another binding #406

Closed
SalomonBrys opened this issue Feb 22, 2022 · 1 comment
Closed

Provide a way to delegate to another binding #406

SalomonBrys opened this issue Feb 22, 2022 · 1 comment

Comments

@SalomonBrys
Copy link
Member

This follows a use case defined in #384.

Provided and interface I implemented by a class C, if I want to bind C, and have a binding I that delegates to the C binding, I must write:

bind { singleton { C() } }

bind<I> { provider { instance<C>() } }

This second line is not immediately understandable and requires some mental gymnastic to understand what is a simple delegation.

I propose the following DSL to make this usecase easier to read:

bind { singleton { C() } }

bind<I> { sameAs<C>() }
@romainbsl
Copy link
Member

final syntax is

interface ICache
class Cache : ICache

val di = DI {
    bind { singleton { Cache() } } // Bind concrete type
    delegate<ICache>().to<Cache>() // Delegate binding to concrete bound type
}

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

No branches or pull requests

2 participants