nhaarman / acorn

Mastering Android navigation :chipmunk:
https://nhaarman.github.io/acorn
Apache License 2.0
181 stars 7 forks source link

Using Dagger to constructor inject Scenes that also receive saved state #143

Open NickvanDyke opened 5 years ago

NickvanDyke commented 5 years ago

Is this possible? How would we tell Dagger what to inject for the Scene's savedState constructor parameter? For the time being I have switched to using Koin since with that I can locate the Scene's dependencies, and pass those and the savedState into the Scene's constructor manually.

To be clear, what I'm looking to be able to do is annotate my Scene with @Inject, and then either retrieve it through appComponent.getSomeSpecificScene() or let Dagger inject it into other classes. In both scenarios, the Scene is constructed entirely by Dagger.

Zhuinden commented 5 years ago

How about assisted injection? https://youtu.be/9fn5s8_CYJI?t=2080

nhaarman commented 5 years ago

I don't use Dagger myself, but something @Zhuinden mentioned should be possible I guess? Doesn't Dagger support such a thing out of the box? 🤔

This is one thing we do encounter by the way, dealing with clean dependency injection. You can create really nice dependency scopes, but it may cause a fair bit of wiring to set everything up (we do DI manually).

NickvanDyke commented 5 years ago

What @Zhuinden linked works well, thanks guys. Wasn't able to find it with my own googling

nhaarman commented 5 years ago

Nice! Something like this might fit in the documentation :+1: