Should I use DTOs as my data models in MVVM?

前端 未结 3 1664
死守一世寂寞
死守一世寂寞 2021-02-04 12:34

I\'m currently working on what will be my first real foray into using MVVM and have been reading various articles on how best to implement it.

My current thoughts are to

3条回答
  •  -上瘾入骨i
    2021-02-04 12:56

    I decided to have a property "Model" on my ViewModel. In the model itself I already implement IPropertyNotifyChanged and IDataErrorInfo. In my ViewModel I thus skip properties where the code would simply "fall-through" to the model. Instead, the View binds directly to the model for those properties.

    For more complicated cases, where I have to adjust the data in the model to fit the view, I do this in the ViewModel. Also, the commands, etc. are in the ViewModel. But I do not see the reason to have boilerplate code in the ViewModel repeating the same stuff which I already have in the model.

提交回复
热议问题