
Enables dynamic, annotation-free dependency injection with flexible management options. Supports various injection types like Provide, Singleton, Bind, and BindSingleton for efficient dependency handling.
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!
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!