https://kotlinlang.org logo
Title
k

Kirill Rozov

01/12/2020, 3:01 PM
The second issue is constructor lazy & provider injection into constructor. It’s bad to have required dependencies of a component into properties because DI library can’t do that
I have written
Proxy<T>
and
Lazy<T>
wrappers that resolve dependencies lazy and it will be good to have it build in the library
a

arnaud.giuliani

01/15/2020, 8:16 AM
Can you give a example?
k

Kirill Rozov

01/15/2020, 8:20 AM
class Artifact(
   lazyDep: Lazy<Dep1>
   proxyDep: Proxy<Dep2>
)
module {
    single {
         Artifact(lazyDep = lazy<Dep1>(), proxyDep = proxy<Dep2>())
    }
}
It allows injection in a constructor without resolve dependencies immediately
a

arnaud.giuliani

01/15/2020, 8:21 AM
yes I see
can't we use
inject()
here? 🤔
k

Kirill Rozov

01/15/2020, 8:23 AM
Very important to have static analyzer rule to check confusing between
get
and
lazy
,
provider
In my own implementation
module {
    single {
         Artifact(lazyDep = get<Dep1>(), proxyDep = get<Dep2>())
    }
}
But will be never successfully resolved
can’t we use
inject()
here? 🤔
Do you mean property injection ?
a

arnaud.giuliani

01/15/2020, 8:23 AM
no I mean, we have
get
to resolve directly
... I don't have the Koin codebase under the hand 😛
k

Kirill Rozov

01/15/2020, 8:26 AM
no I mean, we have
get
to resolve directly
But it resolve all dependencies in a constructor when I’ll get
Artifact
. But I want to resolve them lazy
a

arnaud.giuliani

01/15/2020, 8:26 AM
sure I see