https://kotlinlang.org logo
#android
Title
# android
c

curioustechizen

04/06/2017, 8:53 AM
@nhaarman @bulwinkel How then do you propagate dependencies through the layers without the intermediate layers having to simply forward dependencies to the lower layers?
n

nhaarman

04/06/2017, 9:00 AM
By propagating dependencies through the layers and simply forward dependencies to the lower layers.
c

curioustechizen

04/06/2017, 9:01 AM
Sure but isn't that a lot of boilerplate? Especially when often the intermediate layer does not need to know anything about a particular dependency?
n

nhaarman

04/06/2017, 9:15 AM
then you may need another layer of abstraction
c

curioustechizen

04/06/2017, 9:15 AM
Hmm good point
But in any case for me the purpose of using Dagger is to move the boilerplate associated with injecting dependencies into one place so that my actual code is less noisy
n

nhaarman

04/06/2017, 9:22 AM
sure, but Kotlin's
lazy
removes a lot of that boilerplate
and the last time I worked with Dagger, I had to write a lot of boiler plate as well to tell Dagger which implementations to use for the interfaces
👍 2
c

curioustechizen

04/06/2017, 9:26 AM
Yes - that's why when talking about dagger I prefer to say "move the boilerplate" rather than "eliminate boilerplate" 😛
Could you provide an example of how using
lazy
can be used for DI?
b

bulwinkel

04/06/2017, 10:33 AM
I also don't mind the little bit of boilerplate involved in the propogation as it makes it easier to trace back to the source of the dependency
👍 1
n

nhaarman

04/06/2017, 10:46 AM
That was one of the reasons I stripped our application of Dagger, it was sometimes confusing as to where the dependencies came from
Copy code
class ApplicationComponent {

  val foo by lazy { Foo() }

  val bar by lazy { Bar(foo) }

}

class Presenter(val bar: Bar)

val presenter = Presenter(ac.bar)
🤔 2
c

curioustechizen

04/06/2017, 12:05 PM
I'll explore this idea. Thanks!
I'm thinking about what this might look like without dagger - https://github.com/googlesamples/android-architecture/blob/todo-mvp-clean/todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksPresenter.java#L55 I'm also wondering how to use
lazy
to inject a dependency into an object that you don't instantiate yourself (like an Activity). I'll explore a bit and share my findings here hopefully 🙂
n

nhaarman

04/07/2017, 7:21 AM
You'd get the reference to the activity the same way Dagger would get it
c

curioustechizen

04/07/2017, 7:26 AM
I'll probably have to spend half a weekend and write some code before I can comment 🙂