Michal Baran
Sep 1, 2018 · 1 min read

In current solution, every time MoviesActivity is created, a new instance of MoviesPresenterFactory will also be created, but method create() will be invoked only once, because existing instance of MoviesPresenter will be used after configuration changes.

Thanks to using Providers, instance of eg. MoviesRepository is created when get() is invoked and because get() is in create() method, it’s invoked only once. On the other hand, if we were passing MoviesRepository directly to MoviesPresenterFactory Dagger would have to create an instance of MoviesRepository every time it creates a new instance of MoviesPresenterFactory, which is after every configuration change.

So it’s not really about scopes here, but rather about timing :)

We could achieve similar results with scopes or singletons, but so far I found this solution to be the most lightweight.

Hope this clears things up and if not, please let me know!

    Michal Baran

    Written by

    Android Enthusiast, https://twitter.com/BaranMichal25