我应该使用的DTO作为MVVM我的数据模型? [英] Should I use DTOs as my data models in MVVM?

查看:237
本文介绍了我应该使用的DTO作为MVVM我的数据模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前的工作内容将是我第一次真正涉足使用MVVM并已阅读关于如何最好地实现它的各种物品。

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.

我现在的想法是有效地利用我的数据模型作为数据传输对象,使他们可序列化,并让他们在客户端和服务器端都存在。
这似乎是因为这两种对象类型实际上只是财产的getter和setter的集合一个合乎逻辑的步骤,并在好像完全矫枉过正之间的另一层。

My current thoughts are to use my data models effectively as data transfer objects, make them serializable and have them exist on both the client and server sides. It seems like a logical step given that both object types are really just collections of property getters and setters and another layer in between seems like complete overkill.

显然,将与INotifyPropertyChanged的不是在服务器端正常工作的问题,因为没有视图模型到沟通,但只要我们小心从数据模型构建我国合适的领域模型对象,在业务层和不处理在服务器端的数据模型,我不认为它应该是一个大问题。

Obviously there would be issues with INotifyPropertyChanged not working correctly on the server side as there is no ViewModel to which to communicate, but as long as we are careful about constructing our proper domain model objects from data models in the service layer and not dealing the the data models on the server side I don't think it should be a big issue.

我还没有发现关于我的阅读这种方式太多的信息,所以我想知道这是否是一个pretty标准的事情,这只是假设在做MVVM事实上的方式多层环境?
如果我有完全的事情错误的想法,然后在其他方法的想法是pciated太AP $ P $。

I haven't found too much info about this approach in my reading, so I would like to know if this is a pretty standard thing, is this just assumed to be the de facto way of doing MVVM in a multi-tier environment? If I've got completely the wrong idea about things then thoughts on other approaches would be appreciated too.

推荐答案

我没有这方面的专家。我刚刚同样的情景。我同意你说的那是相当的矫枉过正。我一直在使用这种解决方案很长一段时间,并没有遇到任何问题。该INotifyPropertyChanged的是不是一个大问题,我因为没有在服务器端将订阅PropertyChanged事件。如果您将使用继承您的数据模型,然后都必须是可序列化。在我的方案,我有两个基类为我的数据模型:一个是用于数据传输,另一个没有。

I'm no expert on this. I had just the same scenario. I agree with you that that is quite an overkill. I've been using this solution for quite some time now and haven't encountered any issues. The INotifyPropertyChanged isn't a big problem for me since nothing on the server-side will subscribe to the PropertyChanged event. If you will use inheritance on your data models, then all must be serializable. In my scenario, I have two base classes for my data models: one that is used for data transfer, and the other not.

这篇关于我应该使用的DTO作为MVVM我的数据模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆