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

Unlock the full course today

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

Custom @Scope

Custom @Scope

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

Start my 1-month free trial

Custom @Scope

- [Instructor] In the last video, we met Dagger scope. We also met some of the rules for scoping. In this video, we'll look more carefully at those rules. Here are the rules. Without scope a factory creates a new instance for each request, well, except for Lazy, of course. Scope is an attribute of a creator, an @Binds, an @Provides, or an @Inject constructor. @Component must be annotated with all of the scopes of all of the creators that it uses. Finally, a Component's dependencies may not cause a scoping cycle. The rules against scoping cycles make intuitive sense. Surely, we don't want an object to outlive the scaffolding that created it. On the other hand, it turns out that these rules could have some surprising consequences. Consider the following code. This is a skeleton for code that might well arise in the development of normal Android application. We have a root component, the RootFactory. The root component provides a system-wide environment object. There's also a Presenter…

Contents