Dagger test, androidTest component generated code

to allow Dagger to generate code in test and androidTest folders we should add dependencies test and androidTest to gradle.

Dagger test component not found

Espresso Dagger

Dagger not generating components for /test class

Continue reading “Dagger test, androidTest component generated code”

Provide different implementations of an interface

Use @Qualifier

@Qualifier
@Documented
@Retention(RUNTIME)
public @interface Named {
    /** The name. */
    String value() default "";
}
@Inject
@Named("Database")
Storage storageDB;

@Inject
@Named("Cache")
Storage storageCache;
@Module
public class AppModule {

    @Provides
    @Singleton
    @Named("Database")
    public Storage provideDatabaseStorage() {
        return new Database();
    }

    @Provides
    @Singleton
    @Named("Cache")
    public Storage provideCacheStorage() {
        return new Cache();
    }
}