Questions tagged [dagger]

Dagger is a dependency injection library for Java and Android.

Dagger, by Square, is a fast dependency injection library for Java and Android. It is compatible with JSR 330. Dagger intentionally leaves out some features and imposes some restrictions in order to attain rapid startup times by eliminating slow runtime reflection, especially on Android.

Dagger 2 is a fork maintained by Google which eliminates reflection in the graph generation phase.

For instance, Dagger does not support the following:

  1. Method Injections.
  2. private and final field injections.

Useful Links

1471 questions
11
votes
1 answer

Dagger 2 ContributesAndroidInjector provide activity to module

I'm trying to figure out a less-boilerplate-y way to implement an ActivityModule that is used in all of my app activities. This is my current setup: ActivityModule: @Module class ActivityModule(private val activity: Activity) { @Provides…
Valentin
  • 1,731
  • 2
  • 19
  • 29
11
votes
2 answers

Dagger + Retrofit dynamic URL

PROBLEM I need to call API from domains entered by USER and I need to edit my Retrofit singleton before the call accordingly to the inserted data. Is there a way to "reset" my singleton, forcing it to recreate? or Is there a way to update my…
JakubW
  • 1,101
  • 1
  • 20
  • 37
11
votes
2 answers

flink - using dagger injections - not serializable?

Im using Flink (latest via git) to stream from kafka to cassandra. To ease unit testing Im adding dependency injection via Dagger. The ObjectGraph seems to be setting itself up properly but the 'inner objects' are being flagged as 'not…
ethrbunny
  • 10,379
  • 9
  • 69
  • 131
11
votes
2 answers

Delayed Binding to Dagger2 Graph using Annotation Processing

In this question I talk about Dagger2. Dagger2 consists basically of Components and Modules. Here is an example: Assume I have a interface: public interface MyCoolService { void run(); } and a possible implementation: public class…
user4788711
11
votes
3 answers

Dagger 2 no classes generated

I want to try something new and use Dagger 2 as my DI framework. So I have the following pom and the "hello world" coffee maker classes (http://google.github.io/dagger/) in my projekt. But when I do a mvn clean install no classes get generated. As…
KIC
  • 5,887
  • 7
  • 58
  • 98
11
votes
2 answers

What does @Module means in dagger for android?

I have read many blogs but still i am not able to figure out @Module annotation functioning in dagger. @Inject i got that it provides dependency injection at runtime. But what does @Module does. since the object graph is also built on module. For ex…
anand
  • 1,711
  • 2
  • 24
  • 59
11
votes
1 answer

Android studio gradle duplicate files dagger compiler

having strange problem after updating android studio to 0.4.0 and gradle plugin to 0.7.1 and gradle version to 1.9 with dagger compiler build.gradle android { packagingOptions { exclude 'META-INF/DEPENDENCIES.txt' exclude…
Palaima
  • 331
  • 7
  • 17
10
votes
1 answer

Hilt build fails on CoroutineDispatcher injection

Not sure why this is failing build. Everything seems to be in check class MapObjectRepositoryIMPL @Inject constructor( @ApplicationContext context : Context, val mapObjectDao: MapObjectDao, val barrechatNetwork: BarreNetwork, …
chrisdottel
  • 1,053
  • 1
  • 12
  • 21
10
votes
1 answer

Dagger with Hilt inject ActivityContext in adapter from module

I'm using dagger and hilt and i want to inject @ActivityContext from a module to an Adapter but i'm getting this error - ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.1ANTLR Runtime version 4.5.3…
Naresh NK
  • 1,036
  • 1
  • 9
  • 16
10
votes
1 answer

Dagger: What if I *WANT* a new instance every time?

Interesting how difficult this answer is to find. I've been using Dagger - Android for a while now and have my entire dependency graph set up. I'm using scopes, qualifiers, all that good stuff. I'm not a Dagger newbie anymore, but suffice to say…
Codepunk
  • 188
  • 1
  • 12
10
votes
2 answers

Access Dagger subcomponent dependencies from parent android module

Recently I started to divide our application into smaller Android modules, but I'm having a hard time to make Dagger work the way I want it to. My current dagger setup consist of: - ApplicationComponent marked with @Singleton. This component is…
Eixx
  • 313
  • 2
  • 14
10
votes
1 answer

Dagger2 issue with "cannot be provided without an @Provides-annotated method."

I'm trying to setup a new project with Dagger2, I've used Dagger2 before, but now I'm trying to set it up from scratch by myself. I'm getting the example from a Kotlin project that I'm part of, but can't set it up for Java the same way as it works…
10
votes
1 answer

What is the use of @Reusable scope in Dagger 2

I'm trying to understand the use of the @Reusable scope of Dagger. From the documentations what I can understand is that if a provider is scoped with @Singleton or any other custom scope, then the object will be created first and then cached for the…
user4260260
10
votes
1 answer

How to inject singleton in Android Service with dagger 2

I'm trying to add a singleton Manager into an Android Service. The problem is that the injected manager is not the same as the one in the ViewModel. Dagger Component @Singleton @Component(modules = {ApplicationModule.class, AppScreenModule.class,…
tasegula
  • 889
  • 1
  • 12
  • 26
10
votes
2 answers

How to test a REST API that uses Retrofit and Dagger2

I would like to create a unit test that verifies that the API successfully gets the List of Repos. I would like that the test actually makes the network connection instead of using a Mock Server. And also, would be good to use RoboElectric for…
Kenenisa Bekele
  • 835
  • 13
  • 34