In other words, the
@Inject annotation will tell the Dagger what all the dependencies needed to be transferred to the dependant. It’s like the field agents of the iron bank, negotiate with the house and fix the amount of loan th…
Dagger 2 is one of the open source DI frameworks which generates a lot of boilerplate for us. But why is it better than the others? Right now it’s the only one DI framework which generates fully traceable source code in Java which mimics the code that user may write by hand. It means that there is no magic in dependencies graph construction. Dagger 2 is less dynamic than the others (no reflection usage at all) but simplicity and performance of the generated code are on the same level as the hand-written code. In short, Dagger 2 generates all the dependency injection boilerplate for you.
tion that relies on dependency injection, the objects never have to hu…s disappear. The class can easily work with different collaborators and can be tested in isolation. In an application that relies on dependency injection, the objects never have to hunt around for dependencies or construct them themselves. All the dependencies are provided to them or injected into them so that they are ready to be used.
In other words, Dependency Injection in build upon the concept of Inversion of Control. Which says that a class should get its dependencies from outside. In simple words, no class should instantiate another class but should get the instances from a configuration class.
Dependency injection is a technique whereby one object supplies the dependencies of another object. A dependency is an object that can be used (a service). An injection is the passing of a dependency to a dependent object (a client) that would use it. The service is made part of the client’s state. Passing the service to the client, rather than allowing a client to build or find the service, is the fundamental requirement of the pattern.(source)