Sign in Go Pro

Dagger 2

Constructor Injection, Named Injections, Multiple Modules and Graph Composition

This lesson is for PRO members.

Upgrade today to get access to all the PRO lessons.

Unlock this lesson

Up next



In this Lesson you will learn:

  • How to perform constructor injection
  • How to perform method injection
  • How to provide named injections
  • How to require & perform named injections
  • How to create multiple Dagger modules
  • How and why it is important to rely on abstractions (interfaces)
  • How to provide a Retrofit RestAdpater
  • How to build a custom Retrofit Endpoint and inject it into a Restadapter
  • How a multi-module Dagger object graph is composed

- Dagger 2
- Dagger 1
- Dependency Injection Wikipedia Article
- Service Layer Pattern


Hey Donn, I can't compile your project.
When I try this error message appears:

Unsupported method: BaseConfig.getApplicationIdSuffix().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.

I added the above lines. Yet, it don't compile.

implementation ''
annotationProcessor ''
compileOnly 'javax.annotation:jsr250-api:1.0'

Rodrigo, I assume this has to do with the version of Gradle. I'll take a look this afternoon and I'll get back to you with a resolution.

Thanks Donn.

Donn, see whats is happening in my code:

The source code is in red color.
This way I can't Run the app.

First of all , you don't need to work with the same version (till now) of dagger on the course i recommend to use 2.14.1 for dagger dependency and compiler , then to fix the project gradle error just use the latest gradle plugin version
classpath ''
which in turn requires gradle-wrapper version to change too to be
and then sync your gradle version and it should be working fine.
if you faced any problems with importing the project just let me know and i will help you with cuz i already had it working successfully.
i can also share the project code with you if you needed.
Good luck

Ahmed, see whats is happening in my code:

The source code is in red color.
This way I can't Run the app.

Well, I fixed Tasko by myself.
I created a brand new project in Android Studio and fixed all the app, import by import, error by error.
It took me more than 2 hours, but finally I did it.
Now I can proceed in this current lesson.

You need to go PRO to post comments.

Lessons in Dagger 2