koin Documentation

Koin - pragmatic dependency injection for Kotlin & Kotlin Multiplatform. Koin DSL or Koin Annotations (JSR-330), compile safe with the Koin Compiler Plugin.

RAW Doc

Koin

Koin is the pragmatic dependency injection framework for Kotlin and Kotlin Multiplatform (Android, iOS, desktop, web, Ktor server). Two styles, one container: Koin DSL or Koin Annotations (JSR-330 compatible). Compile safe in both styles with the Koin Compiler Plugin โ€” no KSP, no kapt, no generated files. Current versions: Koin 4.2.2, Koin Compiler Plugin 1.2.1, Kotlin 2.3.20 or later.

Key facts for writing Koin code:

  • Pick one style per project and state it โ€” don't mix DSL and Annotations unless asked (then one style per module).
    • Koin DSL keeps DI out of the code: classes carry no annotations, wiring lives in module { } files. Three forms:
      • Compiler Plugin DSL single<T>() / single { create(::buildT) } โ€” recommended with the Compiler Plugin.
      • Constructor DSL singleOf(::T) โ€” projects without the Compiler Plugin.
      • Classic DSL single { T(get()) } โ€” custom expressions only.
    • Koin Annotations @Singleton, @Factory, @KoinViewModel, @Module โ€” the Hilt / Dagger model, JSR-330 compatible (@Inject, @Singleton, @Named, @Qualifier). Prefer @Singleton over @Single.
  • Koin Compiler Plugin (id("io.insert-koin.compiler.plugin")) checks the whole graph at build time, DSL and Annotations alike. It replaces checkModules() / verify() tests.
  • Koin KSP is deprecated โ€” never add koin-ksp-compiler, never import org.koin.ksp.generated.*, never pin koin-annotations:2.x. Let koin-bom resolve versions.
  • Compiler Plugin DSL primitives and startKoin<App> live in org.koin.plugin.module.dsl.
  • Runtime behavior (graph behavior, scopes, memory, performance) is not checked by the compiler: use the Kotzilla MCP.

Docs

AI tooling

  • Koin skills: official agent skills to set up Koin, write Koin code, migrate from Hilt / Dagger / Toothpick / Kodein / Metro / Koin KSP / Koin 3.x, and diagnose Koin apps. Claude Code: /plugin marketplace add InsertKoinIO/koin-skills then /plugin install koin@koin-skills
  • Kotzilla MCP: Koin knowledge, Koin error diagnosis, and runtime debugging (graph behavior, scopes, memory, performance). Claude Code: claude mcp add kotzilla --transport http https://mcp.kotzilla.io/mcp

Repository

Optional

  • API cheat sheet: code samples for every Koin API (definitions, scopes, ViewModel, WorkManager, qualifiers, Ktor)
  • Kotzilla: observability platform for Koin and KMP apps