Upgrading to last version

How to upgrade your code from older version

From Koin 1.0.x

New way to start Koin

Koin 2.0 propose a new way of starting your Koin application. Instead of having multiple startKoin function, related to each extended runtime, we now only have one startKoin fucntion and several ways to extend it for your platform:

In a classical Kotlin file:

Starting Koin

fun main(vararg args: String) {

    startKoin {
        // enable Printlogger with default Level.INFO
        // can have Level & implementation
        // equivalent to logger(Level.INFO, PrintLogger())

        // declare properties from given map
        properties( /* properties map */)

        // load properties from koin.properties file or given file name

        // load properties from environment

        // list all used modules
        // as list or vararg

Starting Koin for Android

In any Android class:

class MainApplication : Application() {

    override fun onCreate() {

        startKoin {
            // use AndroidLogger as Koin Logger - default Level.INFO

            // use the Android context given there

            // load properties from assets/koin.properties file

            // module list

Starting Koin for Ktor

Starting Koin from your Application extension function:

fun Application.main() {
    // Install Ktor features
    install(Koin) {
        // Use SLF4J Koin Logger at Level.INFO

        // declare used modules


At start, Koin log what definition is bound by name or type:

[INFO] [Koin] bind type:'org.koin.example.CoffeeMaker' ~ [type:Single,class:'org.koin.example.CoffeeMaker']
[INFO] [Koin] bind type:'org.koin.example.Pump' ~ [type:Single,class:'org.koin.example.Pump']
[INFO] [Koin] bind type:'org.koin.example.Heater' ~ [type:Single,class:'org.koin.example.Heater']

Import naming changes for DSL

Koin Module DSL hasnโ€™t change much (appart the Scope API that will need entire rework), most changes can then fixed with imports. Take a note that there is no more inner module or visibility rules for this. Module visibility is simple. Those are just list of definitions, visibile everywhere.

org.koin.android.viewmodel.ext.koin.viewModel -> org.koin.android.viewmodel.dsl.viewModel
org.koin.dsl.module.module -> org.koin.dsl.module