kdi
1.0.3indexedEnables dynamic, annotation-free dependency injection with flexible management options. Supports various injection types like Provide, Singleton, Bind, and BindSingleton for efficient dependency handling.
Enables dynamic, annotation-free dependency injection with flexible management options. Supports various injection types like Provide, Singleton, Bind, and BindSingleton for efficient dependency handling.
Surfaced from shared tags and platforms — no rankings paid for.
KDI (Kotlin Dependency Injection) allows you to inject dependencies dynamically, without annotations, and with maximum flexibility.
implementation("io.github.croccio.kdi:shared:{latestVersion}")
implementation("io.github.croccio.kdi:shared-android:{latestVersion}")
First, create your own module:
class MyModule : Module {
override fun register() {
// Define your injections here
}
}
Inside the register method, specify the dependencies you want to inject:
override fun register() {
inject(
Provide { MyClassA() },
Provide { MyClassB() },
// Add more dependencies as needed
)
}
After defining your module, you need to register it—typically when your app starts:
inject(yourModule)
Additionally, you can inject instances at runtime:
inject(Singleton { yourInstance })
To access an injected dependency, use the by injection() delegate:
val myInstance: MyClassA by injection()
KDI provides multiple ways to inject dependencies:
This makes dependency management in Kotlin simple, flexible, and annotation-free! 🚀 New types will be added soon!