首先,在任何人尖叫上当之前,我很难用一个简单的标题来概括它。另一个标题可能是“领域模型和 MVC 模型之间的区别是什么?”或者“什么是模型?”
Conceptually, I understand a Model to be the data used by the views and controller. Beyond that, there seems to be a great deal of differing opinions on what makes up the model. What's a domain model, versus an app model, vs a view model, vs a service model, etc..
例如,在我最近提出的一个关于存储库模式的问题中,有人直截了当地告诉我存储库是模型的一部分。但是,我读过其他一些观点,认为模型应该与持久性模型和业务逻辑层分离。毕竟,Repository 模式不是应该将具体的持久化方法从模型中解耦吗?其他人说,域模型和 MVC 模型之间存在差异。
举个简单的例子。MVC 默认项目中包含的 AccountController。我已经阅读了一些意见,包括帐户代码的设计很差,违反 SRP,等等..。等等。如果要为 MVC 应用程序设计一个“适当的”成员资格模型,那会是什么?
如何分离 ASP.NET 服务(成员资格提供程序、角色提供程序等) 模型上的?或者你根本不会?
The way I see it, the model should be "pure", perhaps with validation logic.. but should be seperate from business rules (other than validation). For example, let's say you have a business rule that says someone must be emailed when a new account is created. That doesn't really belong in the model in my view. So where does it belong?
有人愿意解释一下这个问题吗?