Skip to content

Easy interface binding #429

@morder

Description

@morder

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions