Hi <@U2JKKPMEE>, do you know wether `ViewModel` ca...
# koin
a
Hi @arnaud.giuliani, do you know wether
ViewModel
can have another ViewModel as constructor dependency ? Something like this
Copy code
viewModel { BasketViewModel(get()) }
viewModel { SelectProductViewModell(get(),  basketViewModel) }
k
Hey Andriy, Why do you need that? I'd suggest injecting
repositories
to share state OR inject
use cases
for sharing logic
a
@kzotin I’ve created a simple diagram to show what I need.
Sorry for the quality, if this is not usable I can link draw.io diagram.
@kzotin I was looking for the way to handle such cases (was hoping to avoid ugly Google approach with interfaces passed through activity and fragments )
k
Would suggest to use reactive data types (LiveData or Observable) via shared repository.
SelectProductViewModel
sets value in
ProductRepository
,
BasketViewModel
observes changes
a
good point
@kzotin What if I pass an interface to the
SelectProductViewModel
which is implemented by
BasketViewModel
? The only thing that should be taken into account is lifecycles of the viewmodels otherwise we can face a memory leak.