$ show InsertKoinIO/koin
Koin is a pragmatic, lightweight dependency injection framework for Kotlin and Kotlin Multiplatform. The core library (koin-core) provides a pure Kotlin DSL for defining modules with `single`, `factory`, `scoped`, and `viewModel` definitions, backed by a container (`Koin`, `Scope`, `InstanceRegistry`) that resolves dependencies in O(1) via `HashMap`. The framework supports multiplatform via expect/actual platform abstractions (logging, thread safety, ID generation) and integrates with Android (koin-android: Activity/Fragment scopes, ViewModel, WorkManager, Compose), Ktor (koin-ktor: server plugin, request scope, DI bridge), and Compose Multiplatform (koin-compose: composable application, scope/module lifecycle). Testing is first-class: koin-test provides module verification at build time, mock declaration, and JUnit4/JUnit5 integration. An optional Kotlin compiler plugin (koin-gradle-plugin) adds compile-time safety and auto-wiring, supplementing the classic DSL. The repository includes extensive examples (Android, Ktor, Compose, KMP) and performance benchmarks (JMH, kotlinx-benchmark). The codebase is well-structured with clear separation of concerns, platform-specific source sets, and a rich set of extension modules. Some APIs are marked experimental or deprecated and the compiler plugin requires Kotlin 2.3.20+, but overall the project is actively maintained, with a strong focus on backward compatibility and performance.
The LLM identified 4 files worth highlighting for reuse:
Core scope implementation with thread-safe `_closed` volatile flag, hierarchical scope linking (`linkTo`/`unlink`), parameter stack for injection, and `declare`/`drop` instance management. The design ensures safe concurrent access and clean lifecycle management, reusable as a pattern for any scoped container.
Platform abstraction using Kotlin's `expect`/`actual` mechanism for logging, thread synchronization, ID generation, and class introspection. Demonstrates clean separation of platform-specific code with minimal API surface, reusable in any KMP library.
Provides `Scope.new(constructor)` inline functions that auto-resolve constructor parameters via `get()` at compile time, eliminating reflection. This pattern enables compile-time safety for arbitrary constructor calls and is a non-obvious application of Kotlin's inline reified generics.
Static module verification that analyzes definitions for missing dependencies, circular injections, and optional/injected parameters using Kotlin reflection. The algorithm walks the definition graph and validates each constructor, providing actionable error messages. This is a sophisticated pattern for build-time dependency validation, reusable in any DI framework.