M
M
marmuff2020-01-25 16:51:24
Android
marmuff, 2020-01-25 16:51:24

Using Dagger 2 in a modular architecture - what and how?

Hello.
Now I'm studying multi-module architecture using Clean Architecture + MVP in modules.
Stack: Dagger 2, ReactiveIO (RxJava 2), Picasso, Cicerone, Retrofit 2, OkHttp3
Dagger 2 + Cicerone usage question.
How are they applied (dropping dependencies between modules and starting activities between modules)?
In theory, everything is clear - the interaction between modules through the API (starting an activity, for example, through MyActivityStarter - nothing more), and passing dependencies through component dependencies in Dagger.
But in practice, it doesn't work very well. What would you recommend to read on this topic?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
marmuff, 2020-02-11
@marmuff

So, after poking around in the documentation, it became clear.
The issue with Dagger 2 has not been closed a bit, but in general:
1) If a feature is a third-party functionality that has a mediocre relation to the operation of the application, the Dynamic Feature Module is used (which is very cool, because you can install modules on the fly). A Dynamic Feature Module has its own context and is essentially an "extension". You can use the app module from feature, but you cannot use feature from app directly (more precisely, it is strongly discouraged, but theoretically possible).
2) If this is a small feature related to the direct functionality, the Android Library is preferably used (for example, in the Android Library you can take out networking).
How exactly you can throw classes from a library into an app or feature is understandable, a question with a reverse action (Library does not have an execution context as such, with the exception of fragments and activities). A similar problem can be encountered, for example, by implementing a library stack a la Dagger 2 and Room Persistence Library, when Room requires a context for building. Personally, I decided that I abandoned Dagger at the entry point (i.e. initialized the entry point -> passed the context and only then pulled Dagger) and in the Instance Room building. If there are more acceptable solutions - I will be grateful. Tomorrow I will try to just pick up the app class from the app module and pull the context out of it.
Detailed information on Android Library: https://developer.android.com/studio/projects/andr...
Detailed information on Dynamic Delivery: https : //developer.android.com/guide/app-bundle/dyn...
for the same Room, it is highly recommended to use the application context.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question