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 injection ViewModel Factory compile time error (dependency cycle in dagger)

I receive following error message from dagger at compile time. It finds a dependency cycle in dagger : public abstract interface AppComponent extends dagger.android.AndroidInjector { ^ …
Ali
  • 9,800
  • 19
  • 72
  • 152
1
vote
0 answers

Dagger Android and scope

I am following architecture-components-samples: GithubBrowserSample I have a Viewmodel that has a dependency and is provided through constructor injection, Since App component is singleton dagger forces me to use Singleton scope only if I use any…
Sourabh Saldi
  • 3,567
  • 6
  • 34
  • 57
1
vote
1 answer

Do we really need viewModelFactories and viewmodelProviders when using Dagger?

So I was working on some sample MVVM project using Dagger. I have a viewmodel factory that goes like this: class DaggerViewModelFactory @Inject constructor(private val viewModelsMap: Map, @JvmSuppressWildcards…
linker85
  • 1,601
  • 5
  • 26
  • 44
1
vote
0 answers

Can we add only BaseActivity in ActivityBuilder module as '@ContributesAndroidInjector' instead of mentioning every 'Activity'?

In my application, I am using dagger-2 for Android, I am extending my every activity with BaseActivity which extends DaggerAppCompatActivity. I have created a 'module' (ActivityBuilder) where we are suppose to specify every new activity as…
Prerana
  • 11
  • 1
1
vote
0 answers

Viewmodel not retaining values after changing activities using dagger dependency injection

I'm trying to share a ViewModel between two different activities. The first activity is LoginActivity, there I make a request to an api using the users username and password to get a user object. Using live data that user is then changed in the…
39fredy
  • 1,923
  • 2
  • 21
  • 40
1
vote
2 answers

Dagger2+Retrofit change URL with Subcomponent : cannot be provided without an @Provides- or @Produces-annotated method

I'm newbie in Dagger .I've used this answer to change URL at Runtime. Also I've used three modules and three components as shown below: note : I have tow Components (ApplicationComponent,ActivityComponent) and one Subcomponent(UrlComponent) In…
1
vote
0 answers

How to eliminate the danger of the "Rooms Repository" object.getInstance (app)?

I'm developing an app using MVVM and dagger2. I got a comment about my "Rooms Repository" object.getInstance (app)" is a dangerous object and can cause my app will enter to infinite recursive loop. How can I fix this? My RoomRepository: class…
1
vote
0 answers

Kotlin Error : Dagger does not support injection into private fields private boolean isAppNull;

I am getting this error on a field that is not private. I am trying to inject a boolean field in my MainActivity. This is how I defined my BaseApplication. class BaseApplication : DaggerApplication() { override fun applicationInjector():…
SuvodipMondal
  • 87
  • 1
  • 8
1
vote
1 answer

cannot be provided without an @Provides-annotated method, A binding with matching key exists in component

I'm trying to add dagger2 in a seed project for learn pourposes (I'm not an expert), but i havving the same problem: e:…
1
vote
0 answers

How to get AppComponent instance in a different Module

I'm using dagger in a multi module project. I'm working on a feature module (Gradle module) which is independent of the main App module. The main app gradle module imports my module, so that classes in the main module is not accessible in my module.…
doe
  • 971
  • 2
  • 11
  • 27
1
vote
0 answers

cannot access DataBindingComponent dagger 2

I want to inject data binding to activity using Dagger 2. I have a problem with its. I don't understand what is wrong. ERROR cannot access DataBindingComponent class file for androidx.databinding.DataBindingComponent not found And my code:…
lapwingg
  • 112
  • 9
1
vote
0 answers

How do I with Dagger inject an instance of a class which have a listener as its constructor argument?

How would I inject an instance of GetTodoRepository to MainViewModel when GetTodoRepository requires a listener in its constructor? Obviously the easist solution would be to have setListener() instead of setting it in the constructor or using…
user9591909
1
vote
3 answers

error: @Component.Builder is missing setters for required modules or components in Dagger 2 instead of having setter method

I am new to dagger 2. I was making a CarComponent on kotlin, I was trying to call my DaggerCarComponent with horsePower value without calling petrolEngineModule. the following is my code : import dagger.BindsInstance import dagger.Component import…
SuvodipMondal
  • 87
  • 1
  • 8
1
vote
1 answer

Second initialization of WorkManager

I have to initialize WorkerManager not only once because at Runtime some arguments may change (WorkerFactory()). So I need to call val configuration = Configuration.Builder() .setWorkerFactory(aggregatingWorkerFactory) …
1
vote
1 answer

Dagger2 and ViewModels For Activity and Fragment

I am learning Dagger2 with MVVM Architecture. I have one question I was reading some documents and watching videos. I knew we can reduce lots of boilerplate code for some of the out stuff like singleton pattern and some other stuff that we are…
Harsh Shah
  • 2,162
  • 2
  • 19
  • 39