When to use void Inject in Dagger

1

Dagger, can anyone give me a hand?

I was able to do a 3 simple projects always trying several to have new problems and learn more, but a part I'm kind of copying because I do not understand, Component has some examples that show something like:

void inject(MainActivity activity);

or

void inject(BaseView mView); //Eu sei que o é BaseView e para que serve!!

A question for either Inject . My question is part because in other examples it does not have and often also has one:

Retrofit exposeRetrofit();

or

Context exposeContext();

I have read the documentation but can not see how this works. When I use void inject(...); and when I use Objeto exposeObjeto();

Does anyone know?

    
asked by anonymous 16.11.2017 / 20:01

1 answer

0

When you enter void inject(MainActivity activity); you are setting the MainActivity class to be able to use the instances of the objects that have been defined in the Module. If you needed to use the same component in a Fragment you would also need to define this method there void inject(MeuFragment fragment); .

When you set Retrofit exposeRetrofit(); you are exposing the Retrofit object that you have defined in the Module so that your Activity or Fragment can use it through @Inject Retrofit retrofit; .

I hope I have helped.

    
17.11.2017 / 23:45