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

Module per Fragment / Activity in Dagger

I'm wondering if it is better to have a Module per Activity than a Module per Fragment? In one of my projects, I have an architecture to have a Module per Fragment because I use Activity just to hold and swap Fragments and nothing more. I only…
Eugene
  • 59,186
  • 91
  • 226
  • 333
0
votes
1 answer

Dagger: Problems with addsTo

Currently, i'm trying to add ParentModule to SubModule but the problem is I got some unused @Provider methods even I use it. Here's my code public class DaggerTest extends TestCase { @Inject Random random; public void…
0
votes
1 answer

Injecting fragment and configuration change handling

public class HostActivity extends Activity { @Inject HostedFragment fragment; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_host); …
Morty Choi
  • 373
  • 2
  • 10
0
votes
1 answer

How do make Dagger optional when buildling an SDK in Android/Java?

I am an SDK that will be public for other developers. I have build my SDK using Dagger thus far, but I wouldn't want developers to rely on Dagger when using the SDK. Is there a way to set the @Inject dependencies based on whether dagger has been…
Kamilski81
  • 14,409
  • 33
  • 108
  • 161
0
votes
0 answers

Dagger - No inject registered for members?

I have dagger setup and defined injectables correctly, but getting the following errpr: I saw a couple of similar thread, but the answers didn't solve this java.lang.IllegalArgumentException: No inject registered for…
aryaxt
  • 76,198
  • 92
  • 293
  • 442
0
votes
1 answer

Application Context Using Dagger?

I'm trying to pull Context in to a class using Dagger, here's what I have and the errors that ensue: @Module(injects = { MyApp.class, TransportModule.class }, library = true, includes = { TransportModule.class }) public class AppModule { …
sirvon
  • 2,547
  • 1
  • 31
  • 55
0
votes
1 answer

Android Dagger - having two Modules how to share provider Methods

Let's say i have two modules how would i share modules from one ActivityModule to another module called ModelModule. Here is what i have so far: @Module( includes = ActivityModule.class, library = true, injects= { …
j2emanue
  • 60,549
  • 65
  • 286
  • 456
0
votes
2 answers

android dagger - usefulness of include keyword

What is the 'include' word used for in dagger. For example from the docs here is a module defined like this: @Module( includes = { DripCoffeeModule.class, ExecutorModule.class } ) public class CoffeeAppModule { } Notice how this module…
j2emanue
  • 60,549
  • 65
  • 286
  • 456
0
votes
2 answers

Android Dagger how to perform DI in View components

I am using Dagger and so far its good. I have one module for all the Views (Activities and fragments), and I am injecting them through Object graph. Now I want to include Custom view and my Module looks something like this @Module( injects = { …
SoH
  • 2,180
  • 2
  • 24
  • 53
0
votes
1 answer

Why does my sub-dependency not get set in Dagger?

I am having a hard time figuring out how to inject CachedRithms into my RithmioManager and CachedKamms into my KamilManager? I have the following files: AppScopeModule: @Module ( library = true, complete =…
Kamilski81
  • 14,409
  • 33
  • 108
  • 161
0
votes
1 answer

Dagger and ButterKnife - Can i inject Android AudioManager instance

How do i inject an AudioManager instance ? I need a context and i dont have one ? Here is my class that uses a Dagger injection: public abstract class ListPageActivity extends BaseActivity { private SoundPool mSoundPool; private int…
j2emanue
  • 60,549
  • 65
  • 286
  • 456
0
votes
2 answers

Dagger for Android - cant define injection for class

I cant seem to use the injects word when trying to define classes that will use my injections. Here is my MainModule.java class: import dagger.Module; import dagger.Provides; @Module() public class MainModule { private Context context; …
j2emanue
  • 60,549
  • 65
  • 286
  • 456
0
votes
1 answer

Convert Object to map for retrofit GET

I'm start with Retrofit. I thought of Jackson but has given me problems and I guess there will Retrofit thought about this I have GET endpoints. I need convert this: public class BaseRequest { private String param1; private String param2; …
0
votes
2 answers

need to do nested injections with dagger

I am implementing an MVP in android. I'm using dagger and for some unknown reason, or lack of knowledge, do not get injected into another class . I have this module: @Module( injects = { LoginActivity.class, }, …
0
votes
1 answer

Dagger can't inject a Presenter in my Activities

I'm refactoring an Android app to an MVP architecture, using Dagger 1. My code is more or less the following: public interface View { Presenter getPresenter(); } public abstract class Presenter { // Dagger 1 can't have an abstract class…
Serandel
  • 417
  • 5
  • 20