exxxort
exxxort

Reputation: 13

Using kotlin coroutines in clean architecture

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

Answers (4)

Yakubu
Yakubu

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.

  • I recommend you read some book about clean architecture, you can get from amazon.
  • You can also get some practical guide on medium.

here is are sample

Android clean architecture1

Android clean architecture2

Upvotes: 0

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

MaryG
MaryG

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

besodev
besodev

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

Related Questions