Reputation: 13
I am a beginner android developer. I'm just starting to learn clean architecture. Is it practical to have kotlin coroutines dependency in domain layer? As I know domain don't need have dependencies.
I want to use coroutine inside my UseCase class, but I don't know if it's right
Upvotes: 1
Views: 845
Reputation: 1119
Domain layer should not depend on outside module like data layer or presenter layer, you can use a constructor parameter to inject to your usecase which is best approach and let other dependency library like dagger,hilt or koin handle the dependency for you.
here is are sample
Upvotes: 0
Reputation: 424
I recommend you to use suspend functions, because when you invoke it. On mvvm arquitecture, inside usecase this fuction will force you to use to run on a coroutine.
Upvotes: 0
Reputation: 23
In my app, we are using that in the usecases, injected via Koin's DI. Viewmodels access usecases in order to run their function.
Upvotes: 1
Reputation: 26
As the developers.android documentation says it is ok if you follow the caller's lifecycle. In almost every case, it is ViewModel. But still, you should call it from your ViewModel if you can.
Upvotes: 0