But the moment you instantiate the Module they will be called.
raulraja
06/10/2020, 7:57 PM
So it's the same really. What is your use case?
j
julian
06/10/2020, 9:16 PM
@raulraja Thanks. No specific use case. I was just comparing this technique of DI with Dagger, which offers lazy instantiation. Figuring out the pros and cons of using one vs the other.
julian
06/10/2020, 9:36 PM
It's not such a big loss if we can't have Module implement Data etc when we require that values providing the implementations must be lazy. We could do:
Copy code
val data: Data = Eval.later { InMemoryData() }
class data Module(val data = Eval<Data>, ...)
fun main() {
with(Module.defaultInstance.data.value) {
// Use Data as we would have if Module had implemented Data.
}
}
r
raulraja
06/11/2020, 9:43 AM
Right, you can always replace the inheritance unification of the uber module by composition if you don’t mind the extra wrapping or indirection