Hi, can I bind the same instance to multiple inter...
# kodein
t
Hi, can I bind the same instance to multiple interfaces?
Copy code
interface Feature1 {...}
interface Feature2 {...}

class Service(): Feature1,Feature2 {...}

di {
    bind<Feature1> { singleton {Service()} }
    bind<Feature2> { ... same singleton as above?? }
}
r
You can bind anything for each interface. even something that comes from the DI container itself, like:
Copy code
import org.kodein.di.*

interface Feature1
interface Feature2

class MyService: Feature1, Feature2

val di = DI {
    bindSingleton { MyService() }
    bindSingleton<Feature1> { instance<MyService>() }
    bindSingleton<Feature2> { instance<MyService>() }
}
t
Great! Thank you
118 Views