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

How to filed inject a nullable type in an activity with dagger 2 and kotlin

I have a this dependency that I want to inject in some activity. I'm using dagger.android and did all the setup and the project compiles perfectly In the AppModule: @Provides fun provideAppDrawable(application: Application): Drawable? { return…
Toni Joe
  • 7,715
  • 12
  • 50
  • 69
1
vote
1 answer

Dagger2 & Kotlin: @Binds doesn't work with @IntoMap

I'm doing lesson from here: https://dagger.dev/tutorial/07-two-for-the-price-of-one When I'm changing code @Module abstract class HelloWorldModule { @Binds abstract fun helloWorldCommand(command: HelloWorldCommand): Command } into…
thorin86
  • 604
  • 11
  • 26
1
vote
1 answer

Dagger 2 @Component.Builder dependencies missing setters error

I am trying to instantiate Dagger using some external parameters (I am writing a library) but the compiler keeps giving me the following error: error: @Component.Builder is missing setters for required modules or components: …
Nick Pampoukidis
  • 702
  • 8
  • 28
1
vote
0 answers

Dagger/MissingBinding: android.app.Application cannot be provided without an @Inject constructor or an @Provides-annotated method

Im using dagger in android. in my module I have a method which has a Application dependency. the code below: @Module public class NetworkModule { @Provides public Drawable provideAppDrawable(Application application) { return…
mrzbn
  • 497
  • 1
  • 3
  • 15
1
vote
1 answer

How to handle subcomponents with dagger2 on single activity app?

I'm trying to use dagger 2 on my app. The app has only MainActivity and different fragment which navigation is implemented by the navigation component. I want to have different subcomponents throughout the app such as AuthSubcomponent,…
1
vote
1 answer

Dagger module depends on another module

I'm new to DI and Dagger. I have this dependency graph in the Android project: @Module(includes=[Module1, Module2, Module3]) ClassAModule @Module(includes=[classAModule, Module4]) ClassBModule @Module(includes=[ClassBModule])…
dumbfingers
  • 7,001
  • 5
  • 54
  • 80
1
vote
2 answers

Dagger @Singleton in object module

I have a question if there is any significal difference between using @Module object without @Singleton functions and @Module class with @Singleton functions. So like: @Module object ApiModule { @Provides fun test() } @Module class…
P.Juni
  • 2,365
  • 14
  • 26
1
vote
1 answer

Sci-Chart using Dagger2 for chart update in Android

I am building an app based on arch. MVVM+Databinding for realtime graph data. Using Sci-chart was quick and easy but trying to update app with DI using Dagger2 is generating sci-chart builder instances null while trying to update graph using…
Praween k
  • 1,005
  • 1
  • 10
  • 23
1
vote
0 answers

Managing hk2 and dagger2 in dependencies in gradle

My project, project, used to use HK2 for DI, and now I'm trying to migrate it to using dagger2. It depends on a library, lib, which uses HK2 for DI. Dependencies are managed with Gradle. One of my classes looks like: package com.mine; import…
PunDefeated
  • 566
  • 5
  • 18
1
vote
1 answer

Dagger 2 / Inject Context In A Non-Activity Class

I would appreciate some help with the following problem; I have researched for quite some time, but unfortunately I have not been able to find something that can actually help me. My goal is to inject the applicationContext into a class that is not…
bonobo
  • 132
  • 2
  • 10
1
vote
1 answer

Field injection in AppWidgetProvider in kotlin using dagger 2

I am using dagger2 and kotlin in my project. I have injected activity and viewmodels and now I want to inject appwidgetprovider class for app widgets. I can`t find a way to inject fields in to appwidgetprovider class. Here is my dagger2…
1
vote
1 answer

Dagger: Cannot find symbol error in generated Component code for a Kotlin nested class

I'm trying to @Inject a class Outer that has a nested data class Inner. The dagger generated Component code refers to the nested class as Outer$Inner when Inner is used as a generic type. I'm wondering if there's an annotation (or some other way)…
Pravin Sonawane
  • 1,803
  • 4
  • 18
  • 32
1
vote
0 answers

Dagger Component.Factory cannot be provided

I have a Component to provide dependencies for Data Input: @Component(modules = [DataInputModule::class]) interface DataInputComponent { fun inject(activity: DataInputActivity) fun factory(): Factory @Component.Factory interface…
agiro
  • 2,018
  • 2
  • 30
  • 62
1
vote
1 answer

MockK class verification breaking with Dagger

Overview Expected: Testing Dagger created repository class with empty constructor Issue: Mockk verification is breaking with mockkConstructor and confirmVerified using Dagger dependency injection to create a repository class. When implementing a…
AdamHurwitz
  • 9,758
  • 10
  • 72
  • 134
1
vote
1 answer

Dagger/MissingBinding. Outputter cannot be provided without an @Provides-annotated method

I'm learning Dagger2 via their tutorial but am blocked at part 5. I've implemented everything in Kotlin (jvm) and the logic/behavior matches the tutorial in working order to this point. However, I'm unable to create SystemOutModule and unsure…
es0329
  • 1,366
  • 1
  • 18
  • 35