https://kotlinlang.org logo
#kodein
Title
a

Andreas Sinz

12/11/2017, 10:08 AM
@coletz @darych I'd propose that you use Constructor Injection only in a JVM (non Android) project. Simple example:
Copy code
class Foo(val bar: Bar) {
    fun start() { }
}

class Bar(val baz: Baz)

class Baz()

fun main(args: Array<String>) {
    val kodein = Kodein {
        bind<Foo>() with singleton { Foo(instance()) /* auto retrieve the instance of Bar*/ }
        bind<Bar>() with factory { Bar(instance()) }
        bind<Baz>() with factory { Baz() }
    }

    val foo: Foo =  kodein.instance()
    foo.start()
}
This way your classes do not need to know about
Kodein
or
KodeinInjector
and you are using Kodein to do DI instead of Service locating