문제

The dependent ViewModel gets injected via the constructor (IoC container).

Example: ProductSelectionViewModel uses ShoppingBasketViewModel.

Is this a common practice or is this THE recommended way? I don´t think so...

How should it be done right?

Should the view use the 2 ViewModels? Mediator pattern? Event driven?

Personally I don´t like the last one.

도움이 되었습니까?

해결책

There's nothing wrong with a view model having a direct reference to another view model, if it is a required dependency, then injecting it via the constructor is fine.

If you wish for a view model to be able to create new instances of another view model, then injecting a view model factory type would be the way to go.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top