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
2 answers

How do I get this statement to work in Non Activity Classes?

I need this statement to activate dep. injection.... ((App) getApplication()).inject(this); //or in fragment ((App) getActivity().getApplication()).inject(this);   This statement works fine in Activities and Fragments and…
sirvon
  • 2,547
  • 1
  • 31
  • 55
0
votes
1 answer

Dagger's dependency injection ignored, field remains null

I have 2 modules: AndroidModule for providing Context-related objects and PhotosModule providing PhotoManager. I want to use PhotoManager in PhotosFragment. PhotoManager depends on DbManager, which is provided by AndroidModule. How do I connect all…
EyesClear
  • 28,077
  • 7
  • 32
  • 43
0
votes
1 answer

Dagger, code generation issues for android API < 21

I'm using dagger for dependency injection. I've been building my app and testing it with android Lollipop so far. When i try to run the app in a lower android api then the app crashes. Issues detected. When i launch the app i see a few errors of…
Arthur
  • 3,636
  • 5
  • 19
  • 25
0
votes
1 answer

Injecting my module in Dagger gives me NPE

Im trying to implement a simple example with Dagger where Module returns just a string Module is : @Module( injects = { MainActivity.class } ) public class MyDataModule { public MyDataModule() { } @Provides public MyDataModule…
vicolored
  • 815
  • 2
  • 10
  • 20
0
votes
1 answer

Singleton Dagger2 components

I'm using Dagger2 in a google appengine project and I have several servlets that make use of, what should be, a singleton instance of a given object (MyObject). @Singleton @Component(modules = {MyModule.class}) public interface MyComponent { …
0
votes
1 answer

Unit testing a simple class (with Dagger 1.2)

I think I have some unit testing-dagger missed. I am trying to test a class which implements this Interface: public interface GetAndroidOSVersionInteractor { public String execute (); } The class is this one: public class…
Javier Sivianes
  • 784
  • 1
  • 9
  • 25
0
votes
1 answer

ORMLite with Dagger in Android

Anyone can suggest how to marry ORMLite with Dagger in Android app? Assume I have following layers: UI [Activity] --> Business [POJO] --> DAO [ORMLite] Each layer in injected to 'superior layer' with Dagger. ORMLite creates DAO. Know that there are…
Grzegorz Dev
  • 3,073
  • 1
  • 18
  • 22
0
votes
0 answers

import fizzbuzz not found

I have 'inherited' a source code that I should maintain. It contains import statements about fizzbuzz and dagger that fail. I never used those and am stuck now. Here the dependencies in build.gradle:
michaelsmith
  • 1,011
  • 1
  • 16
  • 35
0
votes
1 answer

Injected object in Application class is null

I have this module: @Singleton @Module(injects = { MyApplication.class }, library = true) public class MyModule { @Singleton @Provides public Configuration provideConfiguration() { Configuration config =…
user4386126
  • 1,205
  • 5
  • 17
  • 32
0
votes
1 answer

Trying to inject singleton into Activity scope to use with Fragment

I'm currently creating a child graph for my activity that extends the application graph. I want to implement the use of singletons on the activity to manage a WebTask that is used by the fragment in the activity. Problem: I cannot get the singleton…
Futureproof
  • 375
  • 4
  • 21
0
votes
1 answer

Cant inject classes using Dagger on Android

I am beggining with Dagger, I am using 1.2 version of it, and I have the following scenario: Module: @Module(injects = { AuthenticationService.class }) public class ServiceModule { @Provides AuthenticationService…
Marcos J.C Kichel
  • 6,887
  • 8
  • 38
  • 78
0
votes
1 answer

How to add generated implementation to Dagger Dependency Graph?

I have an interface public interface SomeInterface { void test(); } and an annotation processor which generates an implementation of SomeInterface called SomeInterfaceImpl. To make this type available with Dagger dependency injection I would…
Michael
  • 32,527
  • 49
  • 210
  • 370
0
votes
1 answer

How to inject different client for retrofit when testing?

Is there any way to change the way to inject, with Dagger, the Retrofit module with different client to the RestAdapter on instrumentation tests? @Provides @Singleton public APIService getAPIService() { RestAdapter restAdapter = new…
Javier Manzano
  • 4,761
  • 16
  • 56
  • 86
0
votes
1 answer

Not getting singletons using Dagger

I am just getting started with Dagger in my current Android app, and I'm not sure how to achieve the functionality I'm looking for (I believe what I'm looking for is possible). Basically, my situation is this. I have the following classes I want to…
TheIcemanCometh
  • 1,055
  • 2
  • 17
  • 31
0
votes
1 answer

Dagger does not initialize Lazy lazy Variable?

I am using Java and Dagger dependency injection framework. Often I have situations where I have to init a class but used later e.g.: private final Message message; public SomePresenter() { message = DaggerComponent.getMessage(); } public…
Michael
  • 32,527
  • 49
  • 210
  • 370