Is it possible to provide an optional type?
I have application data that I'd like to inject, however the data isn't guaranteed at compile time and is fetched during runtime. Is it possible to inject a nullable type?
Currently I get the compile time error: inferred type User? is not a subtype of Any
Thanks in advance.
I guess my question really is, is there a way to provide dependencies outside of the initial startKoin at the beginning? A way to create a new context only when it is needed?
Hello,
Koin doesn't provide any nullable inejction. I think that you could make a component that manage this behavior for you.
For example, you can have a ServiceManager:
ServiceManager(){
var service : Service? = null
fun createService(){
// create your service
}
}
And with Koin, inject the ServiceManager.
Thanks! I think I'm getting the hang of DI practices and such, this makes much more sense.
@arnaudgiuliani Is it something that could be added to Koin? My team members raised that issue lately. I understand the work around and was wondering why it was the case. It's not a technical limitation surely.
Most helpful comment
@arnaudgiuliani Is it something that could be added to Koin? My team members raised that issue lately. I understand the work around and was wondering why it was the case. It's not a technical limitation surely.