Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 1.38 KB

readme.md

File metadata and controls

37 lines (28 loc) · 1.38 KB

Dikt

Dependency Injection library for Kotlin

Maven Central build codecov

import io.github.vantoozz.dikt.dikt
import io.github.vantoozz.dikt.put

data class DBConnection(                        // Some fake service
    val url: String,
)

class MyService(                                // Another service
    private val db: DBConnection,               // depending on the fake one
) {
    fun run() =
        println("Connecting to ${db.url}")
}

fun main() {

    val container = dikt {                      // We're creating a container object
        put {                                   // and putting a definition
            DBConnection("some_url")            // of the fake service
        }                                       // into it
    }

    val myService = container[MyService::class] // And then the container
                                                // creates an object for us

    myService?.run()                            // Prints "Connecting to some_url"
}