kodeinject Build Status Maven Central

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

Usage

Maven

<dependency>
    <groupId>pw.kmp</groupId>
    <artifactId>kodeinject</artifactId>
    <version>1.2.1</version>
</dependency>

Injected

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

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

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

Singleton

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

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

Nullable

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

Paramaters that aren’t required can be annotated with @OrNull, and 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.

compile "pw.kmp:kodeinject:1.2.1"

Related Libraries

kxdate

Kotlin extensions for Java 8 java.time API

Last updated 3 mins ago

vavr-kotlin

Vavr integration for Kotlin

Last updated 3 mins ago

kapsule

Minimalist dependency injection library for Kotlin.

Last updated 3 mins ago

ktunits

Simple unit conversion library for Kotlin

Last updated 3 mins ago

cakeparse

Simple parser combinator library for Kotlin

Last updated 3 mins ago