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

Why subcomponent can't have the same scope as its parent component in dagger

I read one tutorial which talks about the concept of "component" and "Scope" in Dagger. It says: No subcomponent may be associated with the same scope as any ancestor component I understand what it says, but it doesn't explain clearly why…
Leem
  • 17,220
  • 36
  • 109
  • 159
1
vote
1 answer

How to provide Providers using Dagger 2 Multibinding as per the documentation

In reference to https://dagger.dev/multibindings.html, It is stated If you want a map of providers, the Map.Entry objects in your multibound set should include the providers. Then your non-multibound map can have Provider values. I try out the…
Elye
  • 53,639
  • 54
  • 212
  • 474
1
vote
0 answers

How to use @BindsInstance with new dagger-android for runtime injection?

I'm using com.google.dagger:dagger-android 2.24 (not the stock dagger) and couldn't figure out out how to use @BindsInstance for runtime injection. Any help would be appreciated! Application class public class BaseApplication extends…
mco
  • 1,809
  • 15
  • 31
1
vote
0 answers

How can I inject an Interface providing instance of an Activity using Dagger-2.24

I am using Dagger2 for Dependency Injection in Android I have an Interface named FragmentChangeListener which is Implemented by MainActivity. I am trying to providing the instance of MainActivity by using @Binds Annotation but when I use @Inject…
Ganger
  • 91
  • 3
  • 10
1
vote
1 answer

Dagger can't inject a parameter of type interface on a ViewModel's constructor using Dagger Android

Why can't I inject interface types in ViewModel constructors when using Dagger Android? Here's my AppComponent @Singleton @Component( modules = [ AndroidInjectionModule::class, AppModule::class, ActivityBuilder::class, …
Arth Limchiu
  • 304
  • 1
  • 3
  • 14
1
vote
1 answer

How to inject android application class with DispatchingAndroidInjector in dagger 2

I am trying to create a constructor for android application class for injecting DispatchingAndroidInjector as I would like to inject in constructor instead of field injection. Whenever I try to inject inside application class constructor,…
Ct9
  • 150
  • 1
  • 11
1
vote
2 answers

Dagger doesn't generate subcomponent creation method

I'm using dagger 2.24, without dagger-android. My component setup is as follows: @Singleton @Component(modules = [ FirebaseModule::class, ViewModelFactoryModule::class, DispatcherModule::class, NetworkModule::class ]) interface…
Overpass
  • 433
  • 5
  • 12
1
vote
3 answers

Implementing a simple Dagger2 sample

I'm new using Dagger2 (I always used Koin) and I'm trying to implement a simple sample but I don't really know what I'm missing. This is what I got so far. app.gradle: ext.daggerVersion = '2.23.2' implementation…
pawer
  • 43
  • 7
1
vote
1 answer

Dagger - MissingBinding Map,Provider> cannot be provided without an @Provides-annotated method

I'm just starting with Dependency Injection using Dagger Framework, so it might be I'm missing something trivial, but I've spent more than 2 days just going over the code and the tutorial. So, I am trying to use dagger dependency injection for my…
Abbas
  • 3,529
  • 5
  • 36
  • 64
1
vote
1 answer

DaggerComponent cannot find symbol method create() when i use DaggerComponent.builder()

I'm trying to implement a dagger to my Android Project with MVVM structure. I've succeeded in injecting retrofit API service to my ViewModel using Module and Component with a field injection. But I keep getting an error when I try to inject my…
1
vote
2 answers

Troubleshooting gradle file when dagger doesn't auto-generate component code

Update: Link to project -> https://drive.google.com/open?id=1D8mYZL3Pb8FezPp5FOKA20-Um5kTRYxH I had been starting with Dagger and following this tutorial till step 5.4:…
Paras Sidhu
  • 652
  • 1
  • 12
  • 36
1
vote
1 answer

Dagger class cannot be provided without an @Inject constructor or an @Provides-annotated method

Hello I'm new to Dagger and I have crated a simple project to learn more about it. I have a class PermissionManager that has activity as constructor parameter class PermissionManager(activity: MainActivity) { } and my MainFragment has a…
David
  • 3,055
  • 4
  • 30
  • 73
1
vote
2 answers

Mocking dependency not listed in module

I am using very simple and likely very common scenario. Here is my sample dependency: public class MyDependency { @Inject public MyDependency(...) { ... } } I am not listing the above in any module (that is, there is no @Provides for…
ror
  • 3,295
  • 1
  • 19
  • 27
1
vote
2 answers

Exposing Dagger Components defined in an Android Library

How does an Android application in one gradle module include dagger @Modules defined in an other Android Library (.aar)? I'm trying to have a generic library that provides a set of functionality defined thru dagger @Module's able to have have them…
Adam H
  • 118
  • 6
1
vote
2 answers

Dagger 2.21+ unable to generate UnitTest Component in android

Let's start with an issue: > Task :app:kaptAppDebugUnitTestKotlin FAILED /app/build/tmp/kapt3/stubs/appDebugUnitTest/com/pckg/TestAppComponent.java:77: error: [ComponentProcessor:MiscError] dagger.internal.codegen.ComponentProcessor was unable to…
l0v3
  • 963
  • 7
  • 26
1 2 3
99
100