混淆MVC和实体模型 [英] Confussion over MVC and entity model

查看:220
本文介绍了混淆MVC和实体模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的疑虑源自于我正在使用两个不同的演示构建mvc应用程序,即:Steven Sanderson的pro asp.net mvc和在线mvc音乐商店。前者创建一个域模型,将enitiy模型与存储库一起放在一起,而音乐商店演示将实体模型放在mvc模型文件夹中。哪些是最好的方法。实体模型和相关联的存储库应该存在于单独的域层或MVCs模型文件夹中。

My confussion stems from the fact I am using 2 different walkthroughs on building mvc applications, namely: Steven Sanderson's pro asp.net mvc and the online mvc music store. The former creates a domain model, placing the enitiy model in there along with repositories, while the music store demo places the entity model in the mvc model folder. Which of these is the best approach. Should the entity model and associated repositories exist in a seperate domain layer, or in the MVCs model folder.

我是一个真正的noob,所以kis请:)

I'm a real noob to this so kis please :)

谢谢

Stu

推荐答案

分离问题



Asp.net MVC项目模板中的模型文件夹确实非常混乱。大多数开发人员不了解MVC模式,认为应用/域模型=数据模型。大部分时间,情况并非如此。

Separation of concerns

Model folder in Asp.net MVC project template is indeed very confusing. Most developers not knowing enough about MVC pattern think that application/domain model = data model. Most of the time, that's not the case.

以例如可能有几种不同形式的用户实体:

Take for instance a user entity that may be in several different forms:


  • NewUser 是一个应用程序模型实体,具有用户的大多数属性,加上两个密码属性可以声明性地验证

  • 用户 数据模型实体具有所有常用的用户属性和一个密码属性

  • 用户 应用程序模型实体具有所有常用属性, / li>
  • NewUser is an application model entity that has most properties of a user, plus two password properties that can be declaratively validated
  • User data model entity has all usual user properties and one password property
  • User application model entity has all the usual properties and none for password

所以你可以看到这个简单的例子有多个模型彼此不同。而当您有一个多组合的应用程序时,将应用程序模型放在单独的程序集中是非常明智的,因为所有的程序集都可能只能通过这些对象进行通信。没有数据模型实体应该在数据汇编/层之外转移以使用SoC ...

So you can see by this simple example there are multiple models that differ between each other. And when you have a multi-assemblied application, putting application model in a separate assembly is very wise, since all assemblies will most probably communicate using these objects only. No data model entities should be transferred outside data assembly/tier to make use of SoC...

所以最终可以将数据模型放在Model文件夹中构建一个小规模的简单应用程序,但在所有其他情况下,最好使用在所有程序集之间共享的单独的应用程序模型程序集。并且有一个单独的数据模型,仅用于数据层装配。

So in the end it's ok to put data model in the Model folder when building a small scale simple application, but in all other cases it's probably better to use a separate application model assembly that's shared between all assemblies. And have a separate data model that's only used in data tier assembly.

阅读这个答案,可以帮助你看到更清楚的内容。

这一个

Read this answer that may help you see things a bit clearer.
And this one as well.

我建议不要使用Model文件夹,而是使用单独的程序集。您将拥有更好的分离和改进的可扩展性。

I would recommend against using the Model folder and use a separate assembly instead. You'll have better separation and improved scalability.

这篇关于混淆MVC和实体模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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