logo

What is KOIN?

A pragmatic lightweight dependency injection framework for Kotlin developers.

Written in pure Kotlin, using functional resolution only: no proxy, no code generation, no reflection.

Koin is a DSL, a light container and a pragmatic API

Official Website ๐Ÿ‘‰ https://insert-koin.io

Beta version ๐Ÿ‘‰ https://beta.insert-koin.io

Contact & Latest News ๐ŸŒ

Getting Help ๐Ÿš’

Any question about Koin usage?

Reporting issues ๐Ÿ› 

Found a bug or a problem on a specific feature? Open an issue on Github issues

Setup

Current Version

// latest stable
koin_version = '1.0.2'
// current beta
koin_version = '2.0.0-beta-3'

Gradle

Jcenter

Check that you have the jcenter repository.

// Add Jcenter to your repositories if needed
repositories {
	jcenter()    
}

Dependencies

Choose your Koin dependency:

Core features

// Koin for Kotlin
implementation "org.koin:koin-core:$koin_version"
// Koin extended & experimental features
implementation "org.koin:koin-core-ext:$koin_version"
// Koin for Unit tests
testImplementation "org.koin:koin-test:$koin_version"
// Koin for Java developers
implementation "org.koin:koin-java:$koin_version"

Android

// Koin for Android
implementation "org.koin:koin-android:$koin_version"
// Koin Android Scope feature
implementation "org.koin:koin-android-scope:$koin_version"
// Koin Android ViewModel feature
implementation "org.koin:koin-android-viewmodel:$koin_version"

AndroidX


// AndroidX (based on koin-android)
// Koin AndroidX Scope feature
implementation "org.koin:koin-androidx-scope:$koin_version"
// Koin AndroidX ViewModel feature
implementation "org.koin:koin-androidx-viewmodel:$koin_version"

Ktor

// Koin for Ktor Kotlin
implementation "org.koin:koin-ktor:$koin_version"

Quickstart

Declare a Koin module

Write with the Koin DSL what you need to assemble:

// Given some classes 
class Controller(val service : BusinessService) 
class BusinessService() 

// just declare it 
val myModule = module { 
  single { Controller(get()) } 
  single { BusinessService() } 
} 

Starting Koin in Koin 2.0

Use the startKoin() function to start Koin in your application.

In a Kotlin app:

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

In an Android app:

class MyApplication : Application() {
  override fun onCreate(){
    super.onCreate()
    // start Koin!
    startKoin {
      androidContext(this@MyApplication)
      modules(myModule)
    }
  } 
} 

Articles

Articles & resouces about Koin

Talks & podcasts

Koin developers hub

Contributors

This project exists thanks to all the people who contribute. [Contribute]. ekito by koin

OpenCollective

Backers on Open Collective Sponsors on Open Collective

Backers

Thank you to all our backers! ๐Ÿ™ [Become a backer]

ekito by koin

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

ekito by koin ekito by koin ekito by koin ekito by koin ekito by koin ekito by koin ekito by koin ekito by koin ekito by koin ekito by koin

compile "org.koin:koin-core:2.0.0-beta-5"

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