Bestpractice - 混合视图模型域模型 [英] Bestpractice - Mixing View Model with Domain Model

查看:141
本文介绍了Bestpractice - 混合视图模型域模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否合理与域模型视图模型混?

Is it reasonable to mix view models with domain models?

所以即视图模型对象包含一些领域模型对象(而不是其他方式!)

So i.e. the view model object contains some domain model objects (not the other way around!)

推荐答案

一般情况下,你将不得不引用您的域模型在您的视图模型,或至少装载在控制器的域模型,并传递给你的视图的信息模型。

Generally, you will have to reference your Domain Models in your View Models, or at least load the Domain Models in the controllers and pass the information on to your View Model.

我preFER保持控制器和视图一样简单/哑越好,因为这两个领域模型和视图模型是更容易测试。

I prefer to keep Controllers and Views as simple/dumb as possible, because both Domain Models and View Models are FAR easier to test.

所以,我经常引用里面我的视图模型我的领域模型。有时我用聚集,有时我只是(使用自动映射器在有些项目只是普通的旧code,在其它项目)拷贝过来的属性。

So, I often reference my Domain Models inside my View Models. Sometimes I use aggregation, sometimes I just copy over properties (In some projects just with plain old code, in other projects using an auto mapper)

这篇关于Bestpractice - 混合视图模型域模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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