In Kodein 3.x(and possibly older versions), you have access to the property in the initialization of any module with a name kodeinthat you can use in your bindings.
In your module, the binding will look like this:
bind<SomeService>() with singleton { SomeService(kodein) }
For a complete example and using interface separation and implementation, it might look something like this:
interface SomeService {
// ...
}
class DefaultSomeService(val kodein: Kodein): SomeService {
companion object {
val module = Kodein.Module {
bind<SomeService>() with singleton { DefaultSomeService(kodein) }
}
}
val mapper: ObjectMapper = kodein.instance()
// ...
}
You can import the module from the parent, as you noted, and it will get its own link to the current instance of Kodein.
val kodein = Kodein {
import(DefaultSomeService.module)
}
source
share