@Module (Marks classes which provide dependencies. Google creates a module for each Activity. An alternative is to create a module for app level dependencies, a module for Activities, a module for services… you get the idea. Then you can create component interfaces for module groups.)
@Provides (Used inside module classes to mark methods that return dependencies)
@Component (Used to build an interface that Dagger will use to generate the code that will do the dependency injection for us.)
@Named (Sometimes the type alone is insufficient to identify a dependency. For example if you need a Refrofit instance with GsonConverterFactory and another one ScalarConverterFactory you will end up with 2 provide methods that have the same return type: Retrofit. In this case, you can use @Named annotation to differentiate two Retrofit instances.)
@Qualifier @RetentionPolicy (RetentionPolicy.RUNTIME) (You can create your own qualifiers annotations and use them instead of @Named.)
@Singleton (When you use singleton scope, first injected dependency will be cached and all fields would end up having a reference to the same object as long as the component is alive. If the component is destroyed and re-created all cache is lost and everything will be created again.)
@Binds (@Binds provides a replacement of @Provides methods which simply return the injected parameter. If you have provide methods which just call constructor of implementation classes to inject interfaces, you can use @Binds annotation instead to get rid of boilerplate code in your dagger module.)
@Inject
Marks those dependencies which should be provided by Dependency Injection framework.
Mark your constructor with @Inject annotation and all of its dependencies are provided by Dagger. Best way to use dependency injection. In a class you can only mark one constructor with @Inject. An injected constructor magically makes the class injectable too!
Mark a field with @Inject annotation and Dagger will initialize the field for you. An injected field cannot be final or private because Dagger must be able to assign it a value outside of the class.
@Scope
A scope cares about keeping single instance of class as long as its scope exists. In practice, it means that instances scoped in @ApplicationScope lives as long as Application object. @ActivityScope keeps references as long as Activity exists (for example we can share single instance of any class between all fragments hosted in this Activity).
Usually the scope annotations are set for the Component and provide method.
Scope is not necessary for parameters stored within the module. Because the scoped provider isn’t needed for it to provide the same instance. It will only exist once as it is always provided from the field in the module.
If at least one provide method has a scope annotation the Component should have the same scope annotation.
Any time a non-scoped service is being injected by the same component, a new instance of a service is created.
The Component can be unscoped only if all provide methods in all its modules are unscoped too.
All scope annotations for one component (for all modules with provide methods to be a part of Component and for the Component itself) should be the same.
First time a @Singleton scoped service is being injected, it is instantiated and cached inside the injecting component, and then the same exact instance will be used upon injection into other fields of the same type by the same component.
Custom user-defined scopes are functionally equivalent to a predefined @Singleton scope.
Injection of scoped services is thread safe.
Two dependent components cannot have the same Scope.