From the course: Android Dependency Injection with Dagger 2 and Kotlin
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Introducing @Subcomponents
From the course: Android Dependency Injection with Dagger 2 and Kotlin
Introducing @Subcomponents
- [Narrator] In the last video, I introduced component dependencies. Those are factories that depend on other factories. Dagger provides another way of doing this that has some advantages. It's called subcomponents. Syntactically subcomponents are identical to any other component. They can depend on modules or other components. They have factory methods. Basically all the same rules apply. There are two important differences, though. They have a different environment and they are created differently. Let's start by focusing on how a subcomponent is created. Subcomponents are not created with static builder methods. Instead, they are obtained from some other component. To create a component, first add a new method to the parent component. The new method can have any name but it must return the subcomponent type. Finally, the new method must take as arguments instances of any necessary modules whose constructors have arguments. As always modules whose constructors that take arguments…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.