Questions tagged [dagger-2]

Dagger 2 is a dependency injection framework for Java and Android. It implements the full stack with generated code

Dagger 2 is a compile-time dependency injection framework for and .

It uses code generation and compile-time validation taking the approach started with Dagger 1 to it's ultimate conclusion. Dagger 2 eliminates all reflection and improves code clarity by removing the traditional ObjectGraph/Injector in favor of user-specified @Component interfaces. Dagger 2 implements the full stack with generated code.

Useful Links

3161 questions
1
vote
1 answer

Dagger 2 @Inject return Null

I am creating multi module android project using java. I got Null when I inject a class. Followings are my codes. SignupComponent.class @FeatureScope @Subcomponent(modules = SignupModule.class) public interface SignupComponent { …
pak
  • 55
  • 5
1
vote
1 answer

AuthComponent doesn't have a @Subcomponent.Builder, which is required when used with @Module.subcomponents

I am learning Dagger 2 from this site https://developer.android.com/training/dependency-injection/dagger-android. I am creating like this, Appcomponent.java @Singleton @Component(modules = {AppModule.class, AuthModule.class}) public interface…
pak
  • 55
  • 5
1
vote
1 answer

Dagger 2: Field Injection without any provider

While working on a project that uses Dagger 2 for DI, I tried to create a ViewModel and field inject it even without creating any provider from any module. Biggest confusing moment for me since as far as I know Dagger needs to know how to construct…
Bitwise DEVS
  • 2,858
  • 4
  • 24
  • 67
1
vote
1 answer

How to inject a Map using Hilt

I have a setup something like this: interface Animal { } class Dog @Inject constructor() : Animal class AnimalProxy @Inject constructor( val animalFactory: AnimalFactory, val animalMap: Map ) : Animal enum class…
MXC
  • 458
  • 1
  • 5
  • 21
1
vote
0 answers

Dagger 2 - Tatarka DataBinding Conflict

I try to use Dagger 2, but I've got a errors. Adding code below doesn't help me. gradle.projectsEvaluated { tasks.withType(JavaCompile) { options.compilerArgs << "-Xmaxerrs" << "500" // or whatever number you want } } My build.gradle (:app)…
1
vote
1 answer

How to use dependencies from another Module with Dagger2 in Android?

So i Have AppModule and HomeModule. I would like to use in HomeModule the Application context and AppDatabase from AppModule. I'm getting this error: AppDatabase cannot be provided without an @Provides-annotated method. public abstract interface…
Puntogris
  • 325
  • 2
  • 13
1
vote
0 answers

Dagger2 Set up in Java with Ant in Eclipse

I am having trouble in setting up Dagger 2 sample cofee app in Eclipse using Ant. We have huge source code built using Ant so we cannot switch to maven. And I can find no sources anywhere which explains how to do that. I have created a sample…
1
vote
1 answer

Dagger-Hilt: [Dagger/MissingBinding] Object from external Module cannot be provided without an @Inject constructor or an @Provides-annotated method

I am using an AuthenticationRequest object from an external module in my app module. I supply this object as a dependency to my AccountRepository. This is how I have defined my dependency in the app…
GraSim
  • 3,830
  • 1
  • 29
  • 35
1
vote
1 answer

Un-scoped binding in modules vs Constructor injected binding in Dagger

I have an unscoped binding inside the appModule and the same class as constructor injected using the Singleton scope. when I add a declaration inside the appComponent for Foo, the generated code picks up the module binding without any DoubleCheck…
Saurabh Kumar
  • 437
  • 1
  • 5
  • 18
1
vote
2 answers

Android NavHostFragment (fragment) inflation failed with ViewBinding (Using navigation component)

Currently, I am migrating my app to ViewBinding from Kotlin Synthetic. I made all the changes by following the migration guide but after migrating OnboardingActivity. The app is getting crashed when I launch OnboardingActivity. I did google to…
1
vote
1 answer

Inject custom Application class

I am using Hilt and am trying to inject my Application into another activity: @HiltAndroidApp public class MyApplication extends Application { ... } @AndroidEntryPoint public class MyActivity extends AppCompatActivity { @Inject protected…
lostintranslation
  • 23,756
  • 50
  • 159
  • 262
1
vote
1 answer

Dagger/DuplicateBindings with generic interfaces even when using qualifier annotation

I have a base Interface defined like this: @JvmSuppressWildcards abstract class IWorkerContract( private val mContext: Context, // Some other stuff ) { private val ctx: CoroutineScope = CoroutineScope(Job()) // Some other…
Andrew
  • 4,264
  • 1
  • 21
  • 65
1
vote
1 answer

Unresolved reference: DaggerApplicationComponent

For some reason Dagger doesn't generate DaggerApplicationComponent for my component. I tried: rebuilding, cleaning, invalidating cache, restarting Android Studio and etc. Nothing worked for me. Here is the full code: Modules @Module class AppModule…
1
vote
1 answer

How to inject viewmodel factory by dagger 2

Trying to create a view model in a fragment by providing the factory with a dagger but app crashes with error. Move injection to another lifecycle doesn't work E/AndroidRuntime: FATAL EXCEPTION: main Process: com.bigproject.planyourlife, PID:…
OhHiMark
  • 55
  • 1
  • 5
1
vote
1 answer

Dagger 2 - Why am I getting circular reference error?

I have an already working dagger implementation. My android Application class is the one which inits Dagger2 implementation. However when I add a method that uses Activity argument, then I get the dagger error: error: [ComponentProcessor:MiscError]…
htafoya
  • 18,261
  • 11
  • 80
  • 104