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

UninitializedPropertyAccessException: lateinit property pref has not been initialized

I know a similar question has been answered Here. But that was due to butter knife library problem but my case is different. In my case when I use dagger injected properties in my base activity it shows me error Caused by:…
Tarun
  • 1,192
  • 2
  • 11
  • 20
30
votes
1 answer

Dagger 2 constructor injection in kotlin with Named arguments

I have this dependency: @Singleton class SpiceMix @Inject constructor(@field:[Named("oregano")] private val oregano: Spice, @field:[Named("sage")] private val sage: Spice, …
Vas
  • 2,014
  • 3
  • 22
  • 38
30
votes
4 answers

Remove dagger generated classes from Android Studio's global search?

It is really irritating. I need more time to find some class because of dagger 2.
Mladen Rakonjac
  • 9,562
  • 7
  • 42
  • 55
29
votes
2 answers

Update to Kotlin 1.3.30 breaks build with Dagger 2.21

Build error after update from Kotling 1.3.21 to 1.3.30: AppComponent.java:16: error: [Dagger/MissingBinding] java.util.Map, javax.inject.Provider> …
yaroslav
  • 863
  • 1
  • 8
  • 20
29
votes
3 answers

How to exclude Dagger2 classes from test coverage

Is there any option to exclude Dagger2 classes from test coverage report in Android Studio
Mladen Rakonjac
  • 9,562
  • 7
  • 42
  • 55
29
votes
1 answer

Dagger 2: When to use constructor injections and when to use field injections?

I was kind of lazy and used to use almost entirely field injections. I was just providing empty constructor, put my @Inject fields I everything was looking nice and simple. However field injection have its trade-offs so I've devised some simple…
Ognyan
  • 13,452
  • 5
  • 64
  • 82
28
votes
0 answers

error: incompatible types: NonExistentClass cannot be converted to Annotation @error.NonExistentClass()

I am trying to generate Doka docs of my project. While generating I am getting an error like above. I have searched so many but could not able to get solution to this. I have gone through this link also. Here it is saying it might be a dagger…
Divya
  • 289
  • 1
  • 3
  • 5
28
votes
6 answers

java.lang.IllegalStateException: endPosTable already set

Trying to build an alexa (amazon:echo) skills set. At the same time, trying to use this experience as a learning testbed for dependency injection through dagger 2. However, building the package using maven-2 cmd: mvn assembly:assembly…
apil.tamang
  • 2,545
  • 7
  • 29
  • 40
28
votes
2 answers

Dagger 2 injection in non Activity Java class

I am trying to use Dagger2 for DI, it works perfectly fine for Activity/Fragment related classes where there is a onCreate lifecycle event. Now I have a plain Java class which I want to be injected. Any ideas as to how to go about it would be…
Adnan Mulla
  • 2,872
  • 3
  • 25
  • 35
27
votes
4 answers

LiveData is not updating its value after first call

I have been beating my head against the wall and I cannot understand why this is happening. I am working with the new Architectural Components for Android and I am having problems updating a LiveData with a List of Objects. I have two spinners. When…
joao86
  • 2,056
  • 1
  • 21
  • 23
27
votes
1 answer

How can I build a Dagger-based Android library without forcing consuming applications to use Dagger?

I'm working on an Android library that is basically a client for some REST services I've written. I have several storage classes, network queues, parsers, and so on, and like many such classes, they have dependencies on Context or on things like…
Dalbergia
  • 1,699
  • 1
  • 17
  • 26
27
votes
2 answers

Getting rid of Dagger 2 warning "Generating a MembersInjector"

Given the following classes abstract class AbstractClass { @Inject SomeDependency someDependency; } class SomeClass extends AbstractClass { @Inject AnotherDependency anotherDepenency; public void onCreate() { component = // Get…
Sven Jacobs
  • 6,278
  • 5
  • 33
  • 39
27
votes
8 answers

How do I configure IntelliJ/gradle to use dagger 2.0

I have a gradle project and I want to use dagger 2.0 in it. I don't know how to configure IntelliJ and gradle to generate files and let IntelliJ find them? My build.gradle file looks like: apply plugin: 'java' apply plugin: 'idea' version =…
Martijn de Munnik
  • 924
  • 12
  • 23
26
votes
1 answer

@Provides and @Binds methods in same class Kotlin

After dagger 2.11 we can use a @Binds annotation and mark our Module as abstract in this case which is more efficient than a concrete. If my Module has both @Provides and @Binds methods, I have two options : Simplest would be to mark your @Provides…
Sai
  • 15,188
  • 20
  • 81
  • 121
26
votes
1 answer

Can I use Dagger 2's field injection in Kotlin?

I posted a question (Dagger 2 does not generate the component class (Android, Kotlin)), and after some experiments, it seems that the problem might be due to that Kotlin hides the field. class CoffeeShop { @Inject var theCoffee: Coffee? =…
Damn Vegetables
  • 11,484
  • 13
  • 80
  • 135