<@U0BR3D202> <@U0DN57P4Z> How then do you propagat...
# android
c
@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
By propagating dependencies through the layers and simply forward dependencies to the lower layers.
c
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
then you may need another layer of abstraction
c
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
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
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
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
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
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
You'd get the reference to the activity the same way Dagger would get it
c
I'll probably have to spend half a weekend and write some code before I can comment 🙂