Is there a way to inject an object inside an extension function or a global function using DI framework in Android Kotlin?
I use this function in many places. So I do not want to pass a parameter every time.
DI framework can be any of Koin, Hilt, Dagger2, or others.
Something like that:
fun Context.showSomething() {
val myObject = inject()
showToast(myObject.text)
}
Instead of thinking about using Inject you could pass it as a parameter:
fun Context.showSomething(myObject: String) {
showToast(myObject.text)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With