Scoping Activities Subcomponents with dagger-android (1/2)

Minimum Viable Injection

Initial composition of our dagger components
A dagger module class used to specify the android fragments which need injection and how they contribute to the object graph

abstract modules ensure that dagger takes care of all the code involved in the dependency injection of your application, not the developer.

A companion object of an abstract module used to provide statically a dependency. Note that the @singleton does not matter and it could have been any scopes.

Scope are used to manage the lifetime of the objects in your object graph. No scope = a new object each time. A given scope = a single object for the whole scope. The most common scope is the singleton.

In dagger, installing a module into component means that component can contains all the objects provided / bound / held as private members (discouraged) by that module.

Same as for FragmentBuilderModule.kt but for Activities
Not a module used to tell dagger how to build the subcomponent but rather which objects to put in the component.

With dagger-android, we define a subcomponent as the child of another (sub)component by including its builder module to the list of the modules.

The end of the status quo

Problem: (1..N) * Lifetime Activities < Lifetime Object < Lifetime Application

Problem: Lifetime Object = User Session

Some of our activities components needed to become subcomponent of the new User subcomponent which itself would be a subcomponent of the app component.

Screen grab of the official dagger android documentation

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store