Posts Tagged - dagger

Dagger2 (dependency injection)

Dagger2 is a library that allows us to achieve dependency injection. It has three main concepts.

  • @Inject tells dagger which variables to inject.
  • @Module defines how to create the objects that we want to inject.
  • @Component links the two together.

When we make any changes to the data code, we need to rebuild the project and the system will generate for us the classes that we need in order to perform the injections.


Go into and add the following

apply plugin: 'kotlin-kapt'

def daggerVersion = '2.13'

dependencies {
	implementation "$daggerVersion"
	implementation "$daggerVersion
	// kotlin annotation processor
	kapt "$daggerVersion"
	kapt "$daggerVersion"

Read More