Dagger 2 Custom Scope for each Fragment (or Activity etc…)

After reading the answer by @vaughandroid, and What determines the lifecycle of a component (object graph) in Dagger 2? I think I understand custom scopes well enough to answer my own question. First, here are a couple rules when dealing with components, modules, and scoping annotations in dagger2. A Component must have a (single) scope … Read more

How to make Jersey work with Dagger dependency injection?

You shouldn’t think of it as “how to integrate dagger with jersey”. Figure out how to setup jersey, then once you have that figured out, then you can worry about using dagger. Here’s (very roughly) how I would do it. Create your own implementation of the ResourceConfig class. @ApplicationPath(“/service”) public class MyResourceConfig extends ResourceConfig { … Read more

Dagger 2: Cannot be provided without an @Provides-annotated method

Your CoffeeMachine needs CoffeeMaker. And you have declared that Dagger will take care of providing that dependency to the CoffeeMachine by annotating the constructor with @Inject. But Dagger says: CoffeeMaker cannot be provided without an @Provides-annotated method Because you haven’t specified anywhere how CoffeeMaker object should be created. @Injecting SimpleMaker is not enough, because SimpleMaker … Read more

How do you organise your Dagger 2 modules and components? [closed]

EDIT: Let me start out with the fact that this is close to the truth here, but this is an antipattern as described by Martin Fowler’s Data Domain Presentation Layering article HERE (CLICK THE LINK!), which specifies that you shouldn’t have a MapperModule and a PresenterModule, you should have a GalleryModule and a SomeFeatureModule which … Read more

Dagger 2 injecting parameters of constructor

If you’re using modules, then if you have two provider modules bound to the same component, then you’ll be able to allow them to see the heater as a constructor parameter. @Module public class HeaterModule { @Provides @Singleton Heater heater() { return new Heater(); // if not using @Inject constructor } } @Module public class … Read more