How kosi-libs/kodein works
Main Components
• Core DI Module: This is found in the “kodein-di” directory. Its commonMain sources (and platform-specific sources for JVM, JS, Native) implement the heart of dependency injection – the container, binding APIs, instance retrieval, scope management, etc.
• Framework Integration Modules: The “framework” directory contains several subdirectories (android, compose, ktor, tornadofx) which provide specialized integrations for each environment. They extend the core DI functionality and offer idiomatic APIs for each platform. Additional directories like “kodein-di-conf” and “kodein-di-jxinject-jvm” add further configuration or alternative injection paradigms.
• Test & Utility Components: There is a “test-utils” module that provides helper functions, annotations, and sample types to ease testing of DI bindings and resolution.
Relationships and Interactions
• The Core DI Module is at the center and serves as the foundation – all other modules depend on it.
• The Compiler modules (resolver API, processor, test) interact with the core layer. They scan for DI annotations or DSL constructs and generate (or validate) dependency binding code that will be used by the core DI container at runtime.
• Framework-specific modules wrap or extend the core DI container; for example, modules under “framework/android” or “framework/ktor” receive their capabilities by integrating with the core and exposing additional convenience functions/methods tailored to that platform.
• Test and utility modules are used both for actual testing scenarios and serving as examples for correct usage.
Architectural Patterns and Design Principles
• Modular Architecture: The separation into core, compiler, and framework modules indicates a well-organized, modular design that allows users to pull in only the pieces they need.
• DSL-Driven Configuration: As indicated in the README’s example, the DI container is configured via a declarative DSL (a domain-specific language) that defines bindings and scopes.
• Multiplatform Design: The source-set split (commonMain, jvmMain, jsBasedMain, nativeMain) and corresponding tests ensure that the core DI behavior is available on all targeted platforms.
• Compiler Assistance: The use of compiler modules reduces runtime overhead by shifting parts of dependency resolution to compile time (or KSP processing).