Android Dependency Injection with Dagger 2 and Kotlin

Android Dependency Injection with Dagger 2 and Kotlin

1h 53mAdvanced2019-02-01

Authors

G. Blake Meike

G. Blake Meike

Engineer, Architect, and Code Poet

Course details

Dependency injection (DI) is increasingly popular in Android. Injection reduces the amount of code required in an application, reducing debugging overhead. A DI tool like Dagger, which assumes responsibility for creating and providing dependencies of an object, can help make your code cleaner, easier to understand, and easier to test. Dagger 2, the latest version, is particularly highly regarded for its speed and compile-time safety. In this course, Blake Meike teaches Android developers to use Dagger 2 with Kotlin—the newly embraced Android programming language. Review Dagger basics, including the four major types of dependency injection: method, field, lazy, and provider injection. Learn how to use Dagger annotations to declare dependencies, satisfy them, and create reusable modules you can share across your apps. Plus, learn about multibinding and components, the new way of associating modules with injection targets in Dagger 2.

Learning objectives
Dagger basics
Method and field injection
Lazy and provider injection
Dagger annotations: @Module, @Binds, @Provides, and @Named
Multibinding
Components and subcomponents
Singletons and custom scope

Skills covered

KotlinAndroid DevelopmentAndroidMobile DevelopmentGoogleLearningOpen Source

Concepts

Introduction

  • Improve dependency injection with Dagger
  • What you should know
  • Using the exercise files

Basics

  • What is Dagger
  • Why use Dagger
  • Setting up a Dagger project

Essential Dagger

  • Building the graph with @Inject and @Component
  • Introducing Dagger
  • Method and field injection
  • Lazy and provider injection

Modules

  • When Dagger can't figure it out - @Modules and @Binds
  • When it's complicated - @Provides
  • When types are not enough - @Named
  • Multibinding - Sets
  • Multibinding - Maps with simple keys
  • Real-world example - Architecture components #1
  • Real-world example - Architecture components #2
  • Real-world example - Architecture components #3
  • Multibinding - Maps with complex keys
  • Real-world example - Architecture components solved

Components

  • @Components review
  • Extending the builder with @Component.Builder and @BindsInstance
  • @Component dependencies
  • Introducing @Subcomponents
  • @Subcomponents review
  • Extending the subcomponent builder

Scope

  • Rethinking the graph
  • @Singletons and @Reuseable
  • Custom @Scope

Conclusion

  • Next steps
40,000 Toman