My viewModel
implements an interface by delegation like this:
class ProductViewModel(item: Product) : ViewModel(), ItemInterface by ItemDelegator(item)
Now, inside ItemDelegator
I need a CoroutineScope
bound to the ViewModel
I simply cannot do ItemInterface by ItemDelegator(viewModelScope, item)
. When the ViewModel is being created I cannot have a reference to the viewModelScope
1 - Can I somehow "pass" the viewModelScope
to the ItemDelegator
2 - Most of my viewModels lifecycle are bound to the activity lifecycle. Is it ok to pass to the ViewModel the activity lifecycleOwner
(can obtain lifecycleScope
from it) and now, since it is a param in the constructor, I can pass it to the ItemDelegator
?