0% found this document useful (0 votes)
39 views3 pages

Dagger: @module and @provides: Define Classes and Methods Which Provide Dependencies

Dagger provides object dependencies through classes annotated with @Module and methods annotated with @Provides. Classes needing dependencies are annotated with @Inject. The @Component interface connects providers and consumers by enabling modules and performing dependency injection, generating a class prefixed with "Dagger" followed by the interface name. Objects can be marked as singletons using the @Singleton annotation.

Uploaded by

Marc Ivan Lim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views3 pages

Dagger: @module and @provides: Define Classes and Methods Which Provide Dependencies

Dagger provides object dependencies through classes annotated with @Module and methods annotated with @Provides. Classes needing dependencies are annotated with @Inject. The @Component interface connects providers and consumers by enabling modules and performing dependency injection, generating a class prefixed with "Dagger" followed by the interface name. Objects can be marked as singletons using the @Singleton annotation.

Uploaded by

Marc Ivan Lim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Dagger

Object providers - sila ung magbibigay ng mga object sa ibang class. Kung baga

nasa kanila ung mga functions na need ng ibang class at need i share or nagpoprovide

ng dependencies.

@Module and @Provides: define classes and methods which provide dependencies

In Dagger 2, classes annotated with @Module are responsible for providing objects
which can be injected

Such classes can define methods annotated with @Provides. The returned objects from
these methods are available for dependency injection.

-------------------------------------------------------------------------

Object consumers - sila ung mga class na gagamit ng mga object or dependencies

@Inject: request dependencies. Can be used on a constructor, a field, or a method

You use the @Inject annotation to define a dependency. If you annotate a constructor
with @Inject, Dagger 2 can also use an instance of this object to fulfill dependencies. This
was done to avoid the definition of lots of @Provides methods for these objects.

-------------------------------------------------------------------------
Connecting consumers and providers

@Component: enable selected modules and used for performing dependency


injection

The @Component is used on an interface. Such an interface is used by Dagger 2 to


generate code. The base pattern for the generated class is that Dagger is used as
prefix followed by the interface name.

-------------------------------------------------------------------------

You can use the @Singleton annotation to indicate that there should be only one
instance of the object.

You might also like