dependency injection - Dagger and Android context qualifiers -
i've been using dagger in projects while using these examples guides:
https://github.com/square/dagger/tree/master/examples
but there's thing can't comprehend in them. use @foractivity
, @forapplication
qualifiers explicitly differentiate between types of context
, never @inject them in dependency? that? overlook in example?. if quite misleading.
how go injecting them in dependency then? @inject dependency dependency
suffice , resolve correct type own?
to inject context in @foractivity case have to:
@inject @foractivity context context;
here post explains it: https://stackoverflow.com/a/27343567/3929577
it's same result @named annotation.
you can use in module:
@provides @singleton @named("foractivity") context provideactivitycontext() { return activity; }
and use that:
@inject @named("foractivity") context context;
Comments
Post a Comment