I am building an Android app following the Clean Architecture Principles. Here is what I've got:
app module:
- Contains all the Android dependencies.
- Uses MVVM with ViewModel from the arch components.
- ViewModels only communicate with UseCases, which are constructor injected.
usecase module:
- Contains all of the use cases.
- Use cases only communicate with Repositories, which are constructor injected.
repository module:
- Contains all of the repositories.
- Repositories communicate with web services or database etc.
- I have a Retrofit interface defined in this layer, which the repository takes in it's constructor.
data module:
- Contains all the data models
I am trying to use Hilt for dependency injection in the app. I don't want to expose Retrofit, OkHttp etc to the app module because I don't want developers to be able to put network code in the wrong module. Remember, the app module uses ViewModel which can ONLY talk to use cases.
How do I set this up? I tried putting dagger modules in each of these modules to define injection, then in the main app module I included the module from usecase:
@Module(includes = [UseCaseModule::class])
@InstallIn(ApplicationComponent::class)
object AppModule
but this does not work as it starts to complain about not being able to find transitive dependencies in the other modules that I want to keep hidden.