antoniolg / androidmvp

MVP Android Example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DI with your MVP example

juliolopeztorres opened this issue · comments

Hi there!

First of all, very nice and clear example of how MVC could be implemented. I have a couple of questions about it.

On one hand, as we can see in the following image:

image

I usually create/inject/use Domain Classes (my use cases) in Framework Layer directly. The above image show us that we could reach Domain Layer from Framework.
I have re-structured your example in order to clarify C.A. concepts, thinking about Login component, as follow:

image

Now we can see how Framework (Android) has view components and "speaks" with Domain through LoginViewInterface, how Domain "talks" to Data Layer through LoginInteractorInterface (I usually call this Repositories/Services).

Communication is made through interfaces so that we are not violating any C.A. principles.

In your opinion, is that correct?

On the other hand, how could we implement DI (with Dagger 2 i.e.) in this example?

Let say, I would like to make a HTTP POST to BE in order to log me in. I would create a client (Retrofit + Okhttp i.e.) in Application Context and I would inject this client to Data Layer. Should I call Dagger in Data layer? Shoud I pass client's instance through from some where inside Framework Layer (Activity)?

Thank you in advance!

P.D.: I have tried to push a new branch with these changes and made a PR but I couldn't :(

FYI, I have made an example. I inject all dependencies in Activity. As many people create the UseCases (the presenter in some of them) in Activity Context, I let Dagger create those.

Please take a look!

https://github.com/juliolopeztorres/daggerTryOut

I think your structure is good, yeah. I didn't want to mix MVP and clean arch in this same repository, but packages are better the way you mentioned.

For clean arch info, I always recommend the repo from @android10 https://github.com/android10/Android-CleanArchitecture