I am working on an Android application which has the following dependency structure:
The Application layer only depends on the repository layer, and the repository layer depends on the API wrapper layer and the database layer. Therefore, the application layer has no idea about the existence of the API wrapper and database.
Each child layer has its own specific dependencies, which are not exposed to the parent layer. For example, the database layer depends on the Room library, but the repository layer only depends on the database layer without knowing what library is being used under the hood.
I would like to use Koin for Dependency Inject in this application, but I'm not sure how to approach this task. In order to be able to use the dependencies provided by lower layers, I need to add them to the addModules() call while initializing Koin in the Application layer, but I don't have access to lower layers from higher layers.
For example, in order to initialize the database layer's Koin module I need to be able to reference it from the Application layer, but Application layer has no idea about the existence of the database module. It only depends on the repository module.
How would I add these lower layer Koin modules without having a reference to them?
Describe the solution you'd like
It would be great if we could have a way to add modules within modules. For example, if the repository layer's koin module would have something like:
val repositoryModule = module(subModules = [databaseModule, apiServiceModule, networkModule) {
// declarations
}
Describe alternatives you've considered
One possible solution applicable to my situation is to pull the database koin module out of the database layer, and put it into the repository layer so that my application can access it. However, this means that now my repository-layer would need to depend on Room. I'll have compilation errors otherwise.
Target Koin project
Here's the application I'm working on: www.github.com/haroldadmin/MoonShot
you can just write: val repositoryModule = databaseModule + apiServiceModule + networkModule
That is so easy. Thank for you helping!
you can just write:
val repositoryModule = databaseModule + apiServiceModule + networkModule
tnx.
I searched some hours to find a way for this 馃榿.
plz add this to documention.
Most helpful comment
you can just write:
val repositoryModule = databaseModule + apiServiceModule + networkModule