top of page

Android multimodule + MVP + Dagger 2

TLDR;

 

As I often use mutlimodule project with MVP I decided to extract a skeleton for future uses.

Idea is to have app that is divided into couple of modules:

Sceleton contains dagger 2 setup that injects exemplary classes.

The main problem for me when setuping dagger was isolation of modules. Every module knows only about module directly below it. So when I started to define Dagger Modules in corresponding modules the app was not building. I encountered problems such as :

class cannot be provided without an @Provides-annotated method.

I managed to setup skeleton that overcomes all those problems using submodules.

That may be not the only way. But it works for me.

Going from UI to bottom:

ps: sorry for pics, this blog sucks..

 

App module:

UI of our application and context provider. The application type module.

Sees (compiles) the ':repo' and ':presenter' modules.

It supplies

- AppModule (Context provider)

- RepoModule (Repo implementation provider)

to layers below.

AppComponent contains PresenterSubComponent as subComponent.

Presenter module:

Handles the ui logic and forwards execution of business rules to UseCase.

Presenter subcomponent is only dependant of PresenterModule which.

UseCase module:

Build exactly the same as Presenter module. Note that UseCase uses RepoBase - the abstraction of Repo.

Repo Module:

Implementation of our data module's RepoBase.

Data Module

Hope somebody will find it useful. Critique and hints much appreaciated.

Next: Adding rxJava on top of skeleton.

Recent Posts
Archive
Search By Tags
Nie ma jeszcze tagów.
bottom of page