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 builder with @Component.Builder and @BindsInstance

Extending the builder with @Component.Builder and @BindsInstance

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

Start my 1-month free trial

Extending the builder with @Component.Builder and @BindsInstance

- [Instructor] So we've used modules with @Provides annotated methods to show Dagger how to get an object that it can't create for itself. In the past, developers used this technique to pass parameters to Dagger. For reasons that are kind of out of scope for this video but have to do with both efficiency and clarity Dagger now has a better way of doing this. We just saw that a static method builder on Dagger's implementation of a component returns an instance of a builder for the component. The build method on the builder returns any instance of the component. We can inject parameters into a component by extending the component's builder. There are several steps necessary to extend the component builder. I'm going to code up an example in a minute. But first, let me list the steps. First, create a new interface, inside the component. This is a nested interface. Next, annotate the interface with @Component.Builder. Third, the interface must declare a method build() that takes no…

Contents