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

Easy interface binding #429

Open
morder opened this issue Jun 18, 2021 · 0 comments
Open

Easy interface binding #429

morder opened this issue Jun 18, 2021 · 0 comments

Comments

@morder
Copy link

morder commented Jun 18, 2021

Dagger is allowing to do smthg like this

interface IFooDi : IFoo, IFooUi

@Binds
@AppScope
abstract fun fooDi(instance: Foo): IFooDi

@Binds
@AppScope
abstract fun foo(instance: IFooDi): IFoo

@Binds
@AppScope
abstract fun fooUi(instance: IFooDi): IFooUi

but with toothpick, you should write a lot of provider classes like

bind(IFooDi::class.java).to(Foo::class.java).singleton()
bind(IFooUi::class.java).toProvider(FooUiProvider::class.java).providesSingleton()
bind(IFoo::class.java).toProvider(FooProvider::class.java).providesSingleton()

class FooUiProvider @Inject constructor(
    private val instance: IFooDi
) : Provider<IFooUi> {
    override fun get() = instance
}

class FooProvider @Inject constructor(
    private val instance: IFooDi
) : Provider<IFoo> {
    override fun get() = instance
}
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

1 participant