涉及具有领域模型和视图模型的 MVC 的软件设计模式是否有名称?这是使用 AutoMapper 等工具时使用的模式。
我试图向一些程序员同事解释这种设计的优点,并将其称为 MVVM,但我现在认为这是不对的,MVVM 模式是视图阶段为了自己的目的而改进模型,而不是更改控制器和视图之间传递的内容。
当然,这一切都会因为 M 和 V 的数量而变得混乱,我想我应该问问专家,而不是陷入更多的纠结。
Is there a name for the software design pattern that involves MVC with domain models and view models? It's the pattern used when a tool like AutoMapper is employed.
I was attempting to explain the advantages of such a design to some fellow programmers and was calling it MVVM but I'm now of the opinion that's not right and the MVVM pattern is where the view stage is refining the model for its own purposes rather than changing what's passed between the Controller and the View.
Of course it all gets confusing with the number of M's and V's and rather than getting tied up in more knots I thought I'd ask the experts.
发布评论
评论(3)
它称为MVC。不,说真的。您网站的模型恰好称为 ViewModel。
MVC 没有说明模型应该是什么,只是说明它应该如何与 M 和 C 交互。
Its called MVC. No, seriously. Your website's models just happen to be called ViewModels.
MVC doesn't say what the model is supposed to be, just how its supposed to interact with M and C.
正如您可能已经阅读或经历过的那样,Automapper 用于映射对象。说到MVC,V(View)和C(Controller)是非常清楚的。让很多人感到困惑的是M(Model)。 MVC 并不强调如何构建模型。您可以通过运行直接 SQL 查询或使用 ORM 工具(如 NHibernate 或 LINQ2SQL 或您选择的实体框架)来构建模型。
如果你真的想区分这些问题,你可以先行一步,做大多数人所做的事情。您可以引入存储库模式来处理可以使用服务检索的模型数据。在这种情况下,需要使用 Automapper 来映射实体和 Dto。
我认为没有必要简化这种从服务层构建模型的方法。普通的 MVC 在这种情况下也有效:)
As you might have read or experienced that Automapper is used to map objects. When it comes to MVC, the V (View) and C (Controller) are pretty clear. What confuses many people is the M (Model). MVC doesn't lay strong emphasis on how model should be contructed. You can construct your models by running a direct SQL query or using an ORM tool like NHibernate or LINQ2SQL or Entity Framework of your choice.
If you really want to separate the concerns you can go a step ahead and do what most people do. You can introduce repository pattern to handle model data which can be retrieved using a service. This is the situation where Automapper would come into the picture where you need to map entities and Dto's.
I don't think there is any need to abbriviate this method of building models from service layer. The normal MVC stands valid in this case as well :)
“相关”问题为我提供了我认为我能得到的最佳答案。
文章 我们如何做 MVC – 视图模型,合适的 monica 似乎是 MVC-ViewModels 或 MVC-VM。
The "Related" questions provided me with the best answer I think I'm going to get.
The design pattern is defined fairly well in the article How we do MVC – View models and the appropriate monica seems to be MVC-ViewModels or MVC-VM.