MVC、ViewModels、BLL、自顶向下交互
我试图理解 3 层设计,其中 MVC 是(或位于)表示层。具体来说,自上而下的交互概念如何与业务层、ViewModelBuilder 和 MVC 控制器一起工作。
控制器本身是否应该访问 BLL?
ViewModelBuilder 在哪里适合这个?
我刚刚开始理解 MVC 中的模型实际上是 ViewModel,而不是业务或持久模型。我离这里还远吗?
I'm trying to understand a 3-layer design where MVC is (or is in) the Presentation Layer. Specifically, how would the top-down interaction concept work with respect to the Business Layer, a ViewModelBuilder, and the MVC Controller.
Should the Controller itself access the BLL?
Where does the ViewModelBuilder fit in to this?
I'm just starting to understand that the Model in MVC is actually the ViewModel rather than the Business or Persistence Model. Am I way off here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您会感到困惑,因为网上有无数的示例,这些示例没有对简单的 MVC 架构和仅充当大型企业架构中的 UI 层的架构进行任何区分。最有可能的是,您需要后者。
是的,在任何真正复杂程度的应用程序中,您都需要将模型类视为视图模型,然后将它们映射回域模型。查看 Automapper 来帮助自动化此操作。
这里有两篇非常好的文章,对我很有帮助,我认为写得非常好:
http://blogs.msdn.com/ b/simonince/archive/2010/01/26/view-models-in-asp-net-mvc.aspx
http://博客。 msdn.com/b/simonince/archive/2010/12/07/view-model-versus-domain-entity-validation-with-mvc.aspx
Your confused because of the countless examples online that don't make any distinction between a simple MVC architecture and one that is serving as only the UI layer in a larger enterprise architecture. Most likely, you need the latter.
In an application of any level of real sophistication, yes, you'll want to think of your model classes as view models and then map them back to your domain model. Check out Automapper to help automate this.
Here's two really good articles that were helpful to me that I think are really well written:
http://blogs.msdn.com/b/simonince/archive/2010/01/26/view-models-in-asp-net-mvc.aspx
http://blogs.msdn.com/b/simonince/archive/2010/12/07/view-model-versus-domain-entity-validation-with-mvc.aspx