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

Dagger2 : Cannot be provided without an @Inject constructor or an @Provides-annotated method

I've just refactored my dagger code to make it scalable and move all core stuff to a separate module called di. Now when I try to inject my dependencies in the app module I got this : [Dagger/MissingBinding] retrofit2.Retrofit cannot be provided…
Mohammad Sianaki
  • 1,425
  • 12
  • 20
1
vote
1 answer

Why I got NonExistentClass in Kotlin when using AutoFactory?

I use AutoFactory in Kotlin and I receive the issue , I haven't had any issue when I was using java . What is the problem that I receive this issue? TopicLoaderModule_Companion_ProvidePageLoaderViewFactory.java:29: error: cannot find symbol …
I.S
  • 1,904
  • 2
  • 25
  • 48
1
vote
1 answer

Why the dagger graph works works in java but in Kotlin it says missing Provides when I have provided?

I have some issues when converting dagger interfaces from java to Kotlin I got [Dagger/MissingBinding] java.util.Map cannot be provided without an @Provides-annotated method. Here is my interface interface TopicConfigModule { @Binds …
I.S
  • 1,904
  • 2
  • 25
  • 48
1
vote
1 answer

Dagger 2 MissingBinding when swapping concretion for interface

I have two classes that I'm able to have Dagger find and inject for me to use successfully: TrackEvent class TrackEvent @Inject constructor( private val getTrackingProperties: SomeClass ) : UseCase { override suspend…
HBG
  • 1,731
  • 2
  • 23
  • 35
1
vote
0 answers

Android Dagger2 JUnit generated TestComponent class not recognizing/recognized in TestClass

Bit of intro here Project has core and app components Some utility classes are placed in core component to ease the JUnit tests in other modules Dagger is used across all the modules Here is the project structure core ___src ______main …
Mahendran
  • 2,719
  • 5
  • 28
  • 50
1
vote
1 answer

Prefer AndroidInjector.Factory now that components can have factories instead of builders

What does this deprecated warning for AndroidInjector.Builder mean and how do I fix it? AppComponent.kt @Component(modules = [AndroidInjectionModule::class, AppModule::class]) @Singleton interface AppComponent : AndroidInjector { …
Daniel Wilson
  • 18,838
  • 12
  • 85
  • 135
1
vote
0 answers

Unable to inject instance variable using dagger

I am creating the new class manually without injecting through dagger, but all the instances variable in that class should be injected through dagger. For Example: class TestingClass constructor() { @Inject lateinit var test: Test fun…
Stack
  • 1,164
  • 1
  • 13
  • 26
1
vote
2 answers

Kotlin List vs java.util.List generic type inside Java code

I'm stuck with strange behavior while migrating my project to kotlin. It's occurred while i tried to generate dagger injectors. The problem in java or dagger, someone can't resolve kotlin List from generic type Example: interface…
edwardstock
  • 168
  • 2
  • 10
1
vote
0 answers

How to create generic a ViewModelModule for many classes in Android?

I'm using Dagger2 to inject my ViewModel into my fragments. For each fragment I have ViewModelModule as below: public abstract class GameViewModelModule { @Binds abstract ViewModelProvider.Factory bindAppViewModelFactory(AppViewModelFactory…
Pathis Patel
  • 179
  • 1
  • 11
1
vote
1 answer

How to scope dagger dependencies with fragments when using Fragment Factory?

Without using FragmentFactory, scoping dependencies within Fragment is straigth forward. Just create a Subcomponent for your fragment and just create the Fragment's Subcomponent in onAttach(). But when using FragmentFactory you no longer inject…
Archie G. Quiñones
  • 11,638
  • 18
  • 65
  • 107
1
vote
1 answer

Dagger using Provides vs creating a custom class

I am new to Dagger and I came across an alternative to @Provides on some Dagger project and it got me thinking if there was any actual difference between the two methods. Common Code: class DependencyOne { @Inject DependencyOne(); } class…
pojo
  • 11
  • 2
1
vote
1 answer

Dagger 2 dynamic injection when button gets clicked

Not sure if it is possible or not. However, I am looking for a way to solve this. class User(val name: String, val email: String) class MyActivity : AppCompatActivity { @Inject lateinit var vm: MyViewModel override fun onCreate(bundle:…
Chandra Sekhar
  • 18,914
  • 16
  • 84
  • 125
1
vote
3 answers

Is there a way to use injectors in a non-(Activity,Service,Fragment, Application) class

We're using Dagger2 in our application. I am trying to do a room database and I am writing the repository code, but I would like to inject application context and the DAO for the class. I have a feeling that you can only do Dagger injection in…
Kristy Welsh
  • 7,828
  • 12
  • 64
  • 106
1
vote
0 answers

How to inject activity scope object into Application Scope Object?

I'm making an android app and following mvvm architecture through dagger 2. the problem is regarding scoping where Camera preview from activity module want to inject it into AppManager of Application interface DataManager scope. getting error…
Ahsan Ali
  • 171
  • 1
  • 12
1
vote
0 answers

Android inject test dependencies with Dagger: Missing or Conflicting dependencies error

I want to inject dependencies in android tests using dagger. I've created a simple App with an AppComponent extending AndroidInjector. That works for the App itself (the code is built in /build by dagger). Then, for /test I've also created the…
fitu
  • 115
  • 3
  • 13