-
-
Notifications
You must be signed in to change notification settings - Fork 700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use koin in multi-module android project (clean arch)? #472
Comments
Hi, You can then "provide" the Repo as follows:
Our UseCase (we named it Interactor) looks like this:
And the class itsself:
We also have it like this:
|
thank you a lot @SimonHaenle2 for your response. I don't how to answer to that question: If class PoiRepository is in data module then how it is accessible in koin module which is in appPresentation module? or where you put that module? So it seems that I miss something. I have only 3 modules. (Maybe I should have additional global app module?)
file: domain/build.gradle has:
file: data/build.gradle has:
And main application class is in appPresentation module and look like this:
Module with Repo is in appPresentation module and looks like this:
but here is the problem: I have compile error here because the definition of FooBarRepoImpl is not known in appPresentation (and that should be and I want to achieve) |
Presentation has aceess to Domain AND Data. That's correct and in my opinion does not violate the clean architecture. So FooBarRepoImpl in my opinion belongs to data module and should be there. |
Are you sure? when project has such configuration then classes and functions form data module are accessible in appPresentation module. I think it shouldn't happen. appPresentation should not have an idea that data module exists at all. Maybe should be a extra module which would bind all? Or separated configuration of koin in data module and pass to that module "app start event" which starts koin for data module? |
Found a pretty nice tutorial that explains whole project setup here: Also found many other tutorials as well, in all of them presentation has access to domain AND data |
I do have a similar implementation to the one described above, and everything is working like a charm so far. However, I am finding many issues when dealing with instrumented tests. In my case, presentation, domain, and data are libraries/modules of the main project (app). The popular app module is simply used for general purposes, such as configuring and starting Koin, for example. However, it seems Koin is not working well when undertaking instrumented tests (UI tests in my case) on a module, presentation for example. This is part of my test:
The above snippet uses version 1.0.2, although a similar problem arises when upgrading to the recent 2.0.1 version. Basically, the error says something like:
Contrary, I am not having that problem on single-module applications (module app only), so it is clear to me where the problem is. Moreover, no error or issue arises when using Koin for Unit tests. What am I missing? I believe this is also related to issue #380 (comment) Thanks! |
@luna-vulpo I know this is a bit old, but your clean architecture implementation/concept is a bit off. As some others mentioned here, your Simplifying a bit:
As for DI, given that dependency injection is an architectural pattern that manifests separation of concerns at application level, construction concern should be confined to the main module in your application. Library modules should not depend on dependency injection framework that you’re using. To get a bit more context on this topic, I recommend reading Mark Seemmann’s post titled DI-Friendly Library. Mark is probably one of the most authoritative experts in the world in context of dependency injection, so you can trust his judgement |
Presentation should NOT know about Data. That final link you gave is a red-herring as it is only about DI not clean architecture layer dependencies. I suggest looking at what Uncle Bob actually said or the following issue: |
@luna-vulpo You're right. In order to do that while staying 100% faithful to the division, (as you've already noticed) you need a fourth module, lets call it However, this usually comes at quite high inconvenience costs while benefits are negligible for an experienced team. Therefore, in common practice, the tiny |
I struggled with the same question. |
But it DOES know in this example: |
Correct, I always have an extra module called view or presentation for activities and fragments, and I do my DI in app module, app module contains DI, Application class and Manifest only. Here's a project that I wrote while learning Koin and other technologies, I'm not sure if I correctly used the Koin library, but the idea on how to separate Presentation and Data is implemented here https://github.com/tamimattafi/just-do-it |
How about seperate I think that //build.gradle in presentation Module
dependencies {
implementation project(':domain')
} //build.gradle in app Module
dependencies {
implementation project(':data')
implementation project(':domain')
implementation project(':presentation')
} // App.kt in app Module
class App : Application() {
override fun onCreate() {
super.onCreate()
startKoin{
androidLogger()
androidContext(this@App)
modules(listOf(appModule, useCaseModule, repoModule, networkModule))
}
} if you seperate app from I don't know what the answer is, but I solved it with this thought. |
@KimSeongHeon If I have a UserInfoBean map to UserInfoModel, where should I put it? domain layer need know both of them? |
Can you provide some hint (or maybe example or sample) how to proper use Koin in project which use modules to divide into layers according to clean arch.
So the dependences between modules (layer) should be:
Also:
Now I pass about data module to appPresenation (it depends also on data) bacause I cannot figure out how to expose *UseCase classes without providing implementations of *repos
Similar question is here but I cannot figure out solution:
https://www.reddit.com/r/androiddev/comments/akmawy/multimodule_clean_architecture_project_make_koin/
The text was updated successfully, but these errors were encountered: