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

Dagger 1.x @Inject throws an IllegalArgumentException

I want to replace our component registry (with dexfile class loader magic) with an dependency injection framework for Android. The first try is dagger. When trying I get the following error: 11-06 13:05:41.040 16269-16269/com.daggertoolkitexample…
Marko
  • 21
  • 6
0
votes
1 answer

Singleton only in plus'ed dagger graph

I have a Dagger object graph that is able to produce instances of MyClass implicitly, as the constructor of MyClass is annotated with @Inject. I also have a module that I plus onto my existing graph. My goal is for the plus'ed graph, and only for…
Hannes Struß
  • 1,560
  • 2
  • 13
  • 20
0
votes
1 answer

Delivering updated list elements via an otto event to Mortar's screen

I'm trying to use Mortar for a simple application that shows a list of items based on mortar-sample. I'm using Retrofit/Gson to fetch meta-data of these items and Otto to deliver updates to the view once the items are downloaded. I'm also using…
bachr
  • 5,780
  • 12
  • 57
  • 92
0
votes
1 answer

dagger error: Duplicate bindings for java.lang.String

I'm new to dagger and I'm studding it with small app for android. I'm trying to use Retrofit for REST request over http and https to two servers (dev and prod). So I have module in debug flavour where : @dagger.Module(overrides = true, library =…
oleg.semen
  • 2,901
  • 2
  • 28
  • 56
0
votes
1 answer

Dagger : Cannot have two modules unless I mark one as incomplete and have other include the first one?

I have two really simple modules like @Module( injects = { MainActivity.class } ) public class PersonModule { @Provides public Person providePerson() { return new Person(); } } And another…
iTwenty
  • 953
  • 8
  • 19
0
votes
1 answer

Dagger + ButterKnife = Could not initialize class dagger.internal.codegen.ModuleAdapterProcessor

I have a project where I'm using ButterKnife for view injection, and I just added dagger but I'm getting the following error: Description Resource Path Location Type Internal compiler error: java.lang.NoClassDefFoundError: Could not…
Shehabic
  • 6,787
  • 9
  • 52
  • 93
0
votes
1 answer

Dagger dependency injection

Actually i am new to dependency injection and dagger, i have been writing boiler plate code all these time and am trying to learn dagger I have a global class to save preference values @Module(injects = AppPrefes.class) public class AppPrefes { …
George Thomas
  • 4,566
  • 5
  • 30
  • 65
0
votes
1 answer

Why can't I add this module to an existing graph?

I am new to Dagger and DI in general. I am trying to inject a PendingIntent and an AlarmManager object using this following module. @Module( injects = { LocationMonitorService.class, }, library = true, …
nPn
  • 16,254
  • 9
  • 35
  • 58
0
votes
1 answer

Dagger used in Robolectric tests

I want to use Dagger injections in my robolectric tests but I have trouble with set it up. Where is error in my code sample. How can I make this work? My main module @Module( includes = DatabaseModule.class, injects = { …
WojciechKo
  • 1,511
  • 18
  • 35
0
votes
0 answers

Dagger 1.2.2 downgrade to Dagger 1.2.0 for Google Auto Factory

Does anyone know of any side effects of doing this? I'm going to attempt to downgrade to use Google Auto (https://github.com/google/auto/tree/master/factory) since there are a lot of reports of 1.2.1 / 1.2.2 being incompatible. Of course I'm going…
adrian
  • 2,326
  • 2
  • 32
  • 48
0
votes
1 answer

HashMap of Retrofit Classes with Dagger

I'm kinda new to Dependency Injection and I have a doubt. In my app I have a HashMap to store built classes (like a cache) for RetroFit, but now I'm moving to DI with Dagger and I'd like to know how can I achieve the same behaviour. My code: private…
Leonardo
  • 3,141
  • 3
  • 31
  • 60
0
votes
1 answer

How to use dagger in Android Studio Beta 0.8.1

Older version of Android Studio can use this config But the beta version do not have this config. Where can I enable code generation in the beta version?
Bruce
  • 107
  • 5
0
votes
1 answer

Dagger - Provide same class from separate modules

I have some classes which require a specific object to be injected (lets name it ToInject). The problem is that I cannot provide ToInject from separate modules: @Module(injects={OneActivity.class}) public class OneActivityModule { @Provides …
kupsef
  • 3,357
  • 1
  • 21
  • 31
0
votes
1 answer

Child graph with plus(), modules override and buildTypes

What would be an elegant way to create child graphs using ObjectGraph.plus() with different modules according to the buildType? I would like to ObjectGraph.plus(new ModuleA()) for buildType A and ObjectGraph.plus(new ModuleB()) for buildType B (with…
gdelente
  • 776
  • 8
  • 14
0
votes
2 answers

Is it possible to inject dagger ObjectGraph?

I want to create job manager, which jobs could have injectable members. jobManager.queueJob(new Job1()); After job is queued i want to call object graph and inject jobs fields before starting it. What is the proper way to access object graph from…
Alexey Zakharov
  • 24,694
  • 42
  • 126
  • 197