'Is it possible to observe data in domain usecase/interactor?
I want to know if it is possible to somehow observe the data in the domain layer's usecases classes, that are comming from repository. I would wanted to observe live data there, like in activity/fragement:
pictures.observe(...) { pictures -> }
Is it possible with LiveData or Flow?
Solution 1:[1]
I would say that it is against the Clean Architecture principle. LiveData is lifecycle-aware, meaning it respects the lifecycle of other app components, such as activities, fragments, or services. So it should be used in the UI layer.
LiveData.observe() method accepts LifecycleOwner as an argument, so you need somehow to pass the instance of LifecycleOwner to UseCase/Interactor.
There is also LiveData.observeForever() method, which doesn't accept LifecycleOwner object, but LiveData.removeObserver() should be called to stop observing the LiveData.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BigSt |
