Skip to main content

Koin

All you need to setting up Koin in your project

Current Versions

You can find all Koin packages on maven central.

Here are the currently available versions:

ProjectVersion
koin-bomMaven Central
koin-coreMaven Central
koin-core-coroutinesMaven Central
koin-testMaven Central
koin-androidMaven Central
koin-android-testMaven Central
koin-android-compatMaven Central
koin-androidx-navigationMaven Central
koin-androidx-workmanagerMaven Central
koin-composeMaven Central
koin-androidx-composeMaven Central
koin-androidx-compose-navigationMaven Central
koin-ktorMaven Central
koin-logger-slf4jMaven Central

Gradle Setup

Kotlin

Starting from 3.5.0 you can use BOM-version to manage all Koin library versions. When using the BOM in your app, you don't need to add any version to the Koin library dependencies themselves. When you update the BOM version, all the libraries that you're using are automatically updated to their new versions.

Add koin-bom BOM and koin-core dependency to your application:

implementation(platform("io.insert-koin:koin-bom:$koin_version"))
implementation("io.insert-koin:koin-core")

If you are using version catalogs:

[versions]
koin-bom = "x.x.x"
...

[libraries]
koin-bom = { module = "io.insert-koin:koin-bom", version.ref = "koin-bom" }
koin-core = { module = "io.insert-koin:koin-core" }
...
dependencies {
implementation(libs.koin.bom)
implementation(libs.koin.core)
}

Or use an old way of specifying the exact dependency version for Koin:

dependencies {
implementation("io.insert-koin:koin-core:$koin_version")
}

You are now ready to start Koin:

fun main() {
startKoin {
modules(...)
}
}

If you need testing capacity:

dependencies {
// Koin Test features
testImplementation("io.insert-koin:koin-test:$koin_version")
// Koin for JUnit 4
testImplementation("io.insert-koin:koin-test-junit4:$koin_version")
// Koin for JUnit 5
testImplementation("io.insert-koin:koin-test-junit5:$koin_version")
}
info

From now you can continue on Koin Tutorials to learn about using Koin: Kotlin App Tutorial

Android

Add koin-android dependency to your Android application:

dependencies {
implementation("io.insert-koin:koin-android:$koin_android_version")
}

You are now ready to start Koin in your Application class:

class MainApplication : Application() {
override fun onCreate() {
super.onCreate()

startKoin {
modules(appModule)
}
}
}

If you need extra features, add the following needed package:

dependencies {
// Java Compatibility
implementation("io.insert-koin:koin-android-compat:$koin_android_version")
// Jetpack WorkManager
implementation("io.insert-koin:koin-androidx-workmanager:$koin_android_version")
// Navigation Graph
implementation("io.insert-koin:koin-androidx-navigation:$koin_android_version")
}
info

From now you can continue on Koin Tutorials to learn about using Koin: Android App Tutorial

Android Jetpack Compose

dependencies {
implementation("io.insert-koin:koin-androidx-compose:$koin_android_compose_version")
}

You are now ready to start Koin in your Application class:

class MainApplication : Application() {
override fun onCreate() {
super.onCreate()

startKoin {
modules(appModule)
}
}
}
info

From now you can continue on Koin Tutorials to learn about using Koin: Android Compose App Tutorial

Kotlin Multiplatform

Add koin-core dependency to your multiplatform application, for shared Kotlin part:

dependencies {
implementation("io.insert-koin:koin-core:$koin_version")
}
info

From now you can continue on Koin Tutorials to learn about using Koin: Kotlin Multiplatform App Tutorial

Ktor

Add koin-ktor dependency to your Ktor application:

dependencies {
// Koin for Ktor
implementation("io.insert-koin:koin-ktor:$koin_ktor")
// SLF4J Logger
implementation("io.insert-koin:koin-logger-slf4j:$koin_ktor")
}

You are now ready to install Koin feature into your Ktor application:

fun Application.main() {
install(Koin) {
slf4jLogger()
modules(appModule)
}
}
info

From now you can continue on Koin Tutorials to learn about using Koin: Ktor App Tutorial

Koin BOM

The Koin Bill of Materials (BOM) lets you manage all of your Koin library versions by specifying only the BOM’s version. The BOM itself has links to the stable versions of the different Koin libraries, in such a way that they work well together. When using the BOM in your app, you don't need to add any version to the Koin library dependencies themselves. When you update the BOM version, all the libraries that you're using are automatically updated to their new versions.

dependencies {
// Declare koin-bom version
implementation platform("io.insert-koin:koin-bom:$koin_bom")

// Declare the koin dependencies that you need
implementation("io.insert-koin:koin-android")
implementation("io.insert-koin:koin-core-coroutines")
implementation("io.insert-koin:koin-androidx-workmanager")

// If you need specify some version it's just point to desired version
implementation("io.insert-koin:koin-androidx-navigation:1.2.3-alpha03")

// Works with test libraries too!
testImplementation("io.insert-koin:koin-test-junit4")
testImplementation("io.insert-koin:koin-android-test")
}