From the course: Android Dependency Injection with Dagger 2 and Kotlin

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Extending the subcomponent builder

Extending the subcomponent builder

From the course: Android Dependency Injection with Dagger 2 and Kotlin

Start my 1-month free trial

Extending the subcomponent builder

- [Instructor] As I've said, the rules for building subcomponents are pretty much the same as the rules for building components. Before we leave them though, there's one special case that I want to cover. Just like components, subcomponents can take parameters. Just like components, the way to do this is by extending the subcomponent builder. Extending the subcomponent builder is almost exactly the same as extending the component builder. First, add the builder interface to the subcomponent. The rules are the same as they were for components, except that this annotation is at sign subcomponent builder, instead of component builder. Next, the parent component's factory method must return the subcomponent builder, not the subcomponent. Finally, use the parent component's factory method to get the subcomponent builder, add the parameters, and then build. Let's try an example. For this example, I'm going to make the network endpoint a parameter to the presenter factory subcomponent that…

Contents