Koin - a smart Kotlin injection library

to keep you focused on your app, not on your tools




Declare Declare

Use the Koin DSL to describe your components definitions

// Given some classes
class Controller(val service: BusinessService)
class BusinessService()
// just declare it
val myModule = module {
single { Controller(get()) }
single { BusinessService() }
}

Start Start

Just run startKoin function in your application

fun main(vararg args: String) {
// start Koin!
startKoin {
// declare modules
modules(myModule)
}
}

Inject Constructors Inject Constructors

Instances are resolved from your modules

// Controller & BusinessService are declared in a module
class Controller(val service: BusinessService) {
fun hello() {
// service is ready to use
service.sayHello()
}
}

Easy for Android Easy for Android

Just inject into your Android classes

// Just inject in a simple Activity
class MyActivity() : AppCompatActivity() {
// inject BusinessService into property
val service: BusinessService by inject()
}





Special Thanks to our Sponsors ❤️ - Open Collective