Skip to content
⚙️ Constructor dependency injection for Kodein.
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Remove "OrNull" annotation requirement Dec 23, 2017

kodeinject Build Status Maven Central

A small library allowing constructor dependency injection for applications using Kodein.





class Application(db: Database) {
    // stuff goes here

val kodein = Kodein {
    bind<Database>() with singleton { MongoDB("", 27017) }
    bind() from injected<Application>()

kodeinject will automatically instantiate your injected() classes using bindings from the Kodein container.


val kodein = Kodein {
    bind() from injectedSingleton<Application>()

Use injectedSingleton() to cache the dependency instead of creating a new instance for each access.


class Application(db: Database, cache: Cache?) {
    // stuff goes here

Paramaters that are nullable will be set to null if they are unavailable upon injection.

Automatic Kodein injection

class Application(kodein: Kodein) {
    // stuff goes here

Constructors requiring the Kodein object will be injected with it by default, without the need to create a binding.

You can’t perform that action at this time.