nwh
11/13/2018, 2:09 AMgildor
11/13/2018, 2:23 AMCasey Brooks
11/13/2018, 2:47 AMgildor
11/13/2018, 2:48 AMCasey Brooks
11/13/2018, 2:51 AMgildor
11/13/2018, 2:55 AMShawn
11/13/2018, 4:36 AMDavid Hamilton
11/13/2018, 8:03 AMlazy
, what are the advantages of a DI library over using lazy `val`s (singletons) and `fun`s (providers) in a custom Dependencies class?gildor
11/13/2018, 8:08 AMDavid Hamilton
11/13/2018, 8:11 AMgildor
11/13/2018, 8:12 AMDavid Hamilton
11/13/2018, 8:13 AMgildor
11/13/2018, 8:14 AMclass SomeClass(val dep1: SomeDep1, val dep2: SomeDep2)
or the same with method injection (which has a lot of problems, especially in Kotlin with nullability)Other way aroundcould you show an example
David Hamilton
11/13/2018, 8:16 AMopen class Dependencies() {
open val serviceB: ServiceB by lazy {
ServiceB( serviceA)
}
open val serviceA: ServiceA by lazy {
ServiceA()
}
gildor
11/13/2018, 8:16 AMDavid Hamilton
11/13/2018, 8:17 AMgildor
11/13/2018, 8:23 AMDavid Hamilton
11/13/2018, 8:24 AMgildor
11/13/2018, 8:24 AMDavid Hamilton
11/13/2018, 8:25 AMgildor
11/13/2018, 8:27 AMSure, but if I compare with my Guice definitions, it’s hardly, if any, more complicatedIf you use constructor with
@Inject
annotation and your modules mostly just maps interfaces to implementations (or even don’t do this) than Guice or Dagger will save a lot of boilerplate for youDavid Hamilton
11/13/2018, 8:28 AMgildor
11/13/2018, 8:29 AMDavid Hamilton
11/13/2018, 8:34 AM@Provides
annotation in Guice, which yields a Module almost identical to that in the lazy examplegildor
11/13/2018, 8:37 AM@Provides
significantly increase amount of code, but in most cases you actually can avoid this@AssistedInject
for thisDavid Hamilton
11/13/2018, 9:17 AM@Provides
was to allow test contexts to override certain dependencies. Is that possible using @Inject
?gildor
11/13/2018, 9:22 AM