The dagger is an incremental JSR-330 dependency structure with compilation based on Java annotations.
What is dependency injection?
Injection injection (sometimes called Inversion of Control or IoC) is based on the idea that a given class does not need to know how to create or provide classes on which it depends. The provision of these dependencies must correspond to the user class (or to a separate class or factory).
For example, let's say you have a class A , which depends on class B , which depends on classes C and D (In real life, it could be a BusinessLogicClass-dependent application that depends on a calculator and database.) It might look like this:
class A { private B b = new B(); } class B { private C c = new C(); private D d = new D(); }
... but at this point it would be very difficult to use another C or D (calculator or database), even your B (business logic class) should work with different data sources, or if you need to replace any of these parts with a modular testing. Dependency Injection, as a concept, says you should be able to pass dependencies to classes when you create them.
A a = new A(new B(new C(), new D()));
What is dependency injection infrastructure?
The dependency injection framework automatically creates factories for all your classes, so you can create A without worrying about your dependencies or dependency dependencies.
A a = new AFactory().getA();
Dependency development applications typically specify a language for specifying mappings, which are often called bindings, which is just a way to give an indication that you should create an EImpl when the class asks for EInterface or FSubclass when the class asks for a FClass . This language also allows you to choose when to create new instances: for each request, once through the entire application ("singleton") or otherwise. Spring uses XML and Guice uses a custom Java language for this; Dagger uses Java interfaces, classes, and annotations.
You can do dependency injection without a container or framework, but most of the time people think of a framework like Spring, Guice, or a dagger when you mention dependency injection. This framework automates most of the new template, which you see above, which otherwise makes it difficult to work with a "manual" dependency.
What about the JSR 330?
Java has standardized some interfaces and annotations as "JSR 330" to simplify the transition between dependency injection frameworks and to simplify writing libraries that work in any environment. Like Spring and Guice, the Dagger conforms to this standard.
Why is the big deal is that Dagger compile time?
Other dependency injection platforms, including Spring and Guice, do their configuration at run time: they use Java reflection to validate class constructors, methods, and fields. This can be slow in production on servers and desktops, and on Android it is very slow due to differences in VM and mobile processors / memory. Consequently, the Square and Google teams wrote Dagger and Dagger 2 to use Java annotation processing to check classes at compile time and automatically write standard Java code for simple Java objects to act like the plants above. Since it is simple Java without reflection, it can be much faster on Android and embedded systems and can be optimized using existing tools.
Notice also that the Dagger was written in the square by Bob Lee (who originally wrote Guice on Google); The Dagger 2 project rewrites a dagger supported by Google, which changes some features of the dagger setting and how to avoid using reflection. Both daggers and daggers 2 are annotation-based injection frames for Java, but they are slightly different from each other.