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
12
votes
1 answer

Create Custom Dagger 2 Scope with Kotlin

I'm trying to convert a Java code into Kotlin for custom dagger scope creation. Here is Java code: @Documented @Scope @Retention(RetentionPolicy.RUNTIME) public @interface CustomScope { } Once converted into kotlin here is the result…
Abba
  • 519
  • 6
  • 17
12
votes
2 answers

Using @Component.Builder with constructor params

I'm trying to learn dagger and kotlin and mvvm in one so please forgive me if this question is odd. If I have a NetworkModule, which basically provides retrofit to the app, I think it would be a good idea to pass in the base url for which we want to…
Daniel Wilson
  • 18,838
  • 12
  • 85
  • 135
12
votes
3 answers

@Binds methods must have only one parameter whose type is assignable to the return type

I am migrating to the new dagger android 2.11 All set up based on the Google blueprint :MVP-Dagger.but I am having this error : Error:(22, 57) error: @Binds methods must have only one parameter whose type is assignable to the return type Here in…
Mohamed ALOUANE
  • 5,349
  • 6
  • 29
  • 60
12
votes
1 answer

What are the advantages of using DispatchingAndroidInjector<> and the other dagger.android classes?

I'm working on setting up Dagger 2 into my android project. It is my first time with this framework and everything goes well so far. But I'm seeing different approaches on the way you can set up this framework in your project and I wonder which one…
Leandro Ocampo
  • 1,894
  • 18
  • 38
12
votes
4 answers

Dagger 2 does not generate component

I totally exhausted with Dagger 2 in non-Android app (IDE is IntelliJ IDEA). build.gradle buildscript { repositories { maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath…
Alexey
  • 2,980
  • 4
  • 30
  • 53
12
votes
3 answers

Android Retrofit 2 multiple converters (Gson & SimpleXML) error

In my project (I am using Dagger 2, Retrofit 2 & OkHTTP, RxAndroid) i have 2 different API calls. From one I receive JSON, from other - XML. I studied this link and added 2 converters that i need to my…
oleg.v
  • 1,065
  • 3
  • 11
  • 20
12
votes
2 answers

Dagger 2 trouble @Inject-ing FirebaseMessagingService

I recently tried to migrate the application I'm working on from GCM to FCM. While doing so, I found that where I'd previously been using Dagger 2 (2.0.2) to provide instances of my Retrofit APIs and other user-data managers inside the service (with…
Carter Hudson
  • 1,176
  • 1
  • 11
  • 23
12
votes
3 answers

Dagger 2: Unable to inject singleton in other scope

I have Singleton scoped module that provides some standard singletons: Application, DB services, etc. But for Activity I have separate module that should create Presenter for he Activity and I need to pass Application context to it. However I get…
Heisenberg
  • 3,153
  • 3
  • 27
  • 55
12
votes
4 answers

Dagger2 custom @Qualifier usage

Suppose I'm building a car and I have several Brake beans with different implementations class Car { @Inject Car(@BrakeType(value="abs")Brake frontBrake, @BrakeType(value="nonabs")Brake rearBrake) {…
Roger H.
  • 151
  • 1
  • 5
12
votes
1 answer

What's "Dagger will inject those fields if requested, but will not create new instances" means?

In Dagger2's documentation , it say If your class has @Inject-annotated fields but no @Inject-annotated constructor, Dagger will inject those fields if requested, but will not create new instances. Add a no-argument constructor with the …
Ezio Shiki
  • 745
  • 6
  • 23
12
votes
4 answers

Dagger 2 - how to create/provide a EagerSingleton

I am having trouble with the Dagger 2 dependency injection framework. I would like to create an EagerSingleton. I assume that dagger 2 creates lazy loaded singletons when I use the @Singleton annotation. How do I create EagerSingleton using the…
j2emanue
  • 60,549
  • 65
  • 286
  • 456
12
votes
1 answer

Dagger 2 component dependencies

Is it possible to inject something into a module? I have 2 base modules / components: @Component(modules = {OkHttpModule.class}) public interface OkHttpComponent extends AppComponent { OkHttpClient provideOkHttpClient(); } @Module public class…
Ralph Bergmann
  • 3,015
  • 4
  • 30
  • 61
12
votes
4 answers

is @Singleton in dagger 2 thread safe?

I'm trying to move everything in my app away from singletons, because I've been made aware that it's a bad programming practice, with that said, I'm looking into implementing Dagger 2 dependency injection. And I'm wondering, when you do @Singleton…
AlexW.H.B.
  • 1,781
  • 3
  • 25
  • 50
11
votes
2 answers

@CustomTestApplication value cannot be annotated with @HiltAndroidApp

If the Application has a Custom Application object. It is needed to annotate this with @HiltAndroidApp ex: @HiltAndroidApp class AppCore: Application Appcore has some initialization logic which is needed for the app to run Now in the Instrumentation…
11
votes
1 answer

Why is dagger considered better for AWS lambda implementation than Guice?

I know that dagger creates injection at compile time by generating code and hence its performance is better than Guice, which do it at runtime. But specifically for case of lambda, I see it mentioned at multiple places that Dagger is preferred. Is…
hatellla
  • 4,796
  • 8
  • 49
  • 101