ScottPierce / kinject

A simple Kotlin Multiplatform dependency injection library.

Home Page:https://scottpierce.dev/categories/making-a-kotlin-dependency-injection-library/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Kinject

This is from a blog post series on creating a Kotlin Dependency Injection Library. You can find all the posts here.

A multiplatform Dependency Injection library.

Usage

class A

class B(val a: A)

class C(
    val a: A,
    val b: B,
)

val graph = objectGraph {
    singleton(A())                          // Provided Binding
    singleton { B(a = get()) }              // Lazy Binding
    singleton { C(a = get(), b = get()) }   // Lazy Binding
}

val a: A = graph.get()
val b: B = graph.get()
val c: C = graph.get()

About

A simple Kotlin Multiplatform dependency injection library.

https://scottpierce.dev/categories/making-a-kotlin-dependency-injection-library/

License:Apache License 2.0


Languages

Language:Kotlin 100.0%