本文介绍了不将MVC架构用于Web应用程序的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去,我主要使用N层体系结构构建了所有Web应用程序,实现了BLL和DAL层.最近,我开始进行一些RoR开发,并开始研究ASP.NET MVC.

In the past I have primarily built all my web applications using an N-tier architecture, implementing the BLL and DAL layers. Recently, I have started doing some RoR development as well as looking into ASP.NET MVC.

我了解不同体系结构之间的差异(其他SO职位也提到过),但是我真的无法想到为什么我不会为新项目选择MVC模型的任何原因.

I understand the differences between the different architectures(as referenced by some other SO posts), but I can't really think of any reasons why I wouldn't choose an MVC model going forward for a new project.

在您的体验中,是否有任何原因/时间不适合使用MVC架构,或者您为什么选择BLL/DAL架构呢?

Is there any reasons/times in your experience when an MVC architecture would not be suitable, or any reasons why you would choose a BLL/DAL architecture instead?

推荐答案

其中一个因素可能是Web应用程序的状态性.如果它是一个基本的Web应用程序,它通过一些JavaScript钩子(例如客户端验证)从服务器获取所有内容,那么Rails类型的MVC真的很棒.我不熟悉ASP.NET上的MVC,但是我听说它与Rails中的类似.

One of the factors could be the statefulness of your web application. If it's a basic web application that gets everything from the server with a few JavaScript hooks such as client side validations, then the Rails type MVC is really great. I am not familiar with MVC on ASP.NET, but I've heard it's similar to that in Rails.

如果Web应用程序确实是有状态的,那么更好的方法是具有双重MVC层-一层在客户端,另一层在服务器.服务器上的MVC将主要与身份验证,授权,以标准格式转换数据等有关.客户端MVC将与诸如DOM事件,用户操作,它们如何影响应用程序状态以及如何/何时应该请求/发送数据到服务器.

If the web application is really stateful, then a better approach would be to have a dual MVC layer - one on the client side, and the other for the server. The MVC on the server will mostly concern itself with authentication, authorization, churning out data in standard formats, etc. The client side MVC will concern itself with things such as DOM events, user actions, how they affect the application state, and how/when should data be requested/sent to the server.

就像BLL或DAL一样,MVC只是一种组织代码的方式. Rails中的MVC通过使用一组约定从根本上完全隐藏了DAL.通常,业务逻辑驻留在模型本身中.但是,如果您的应用程序需要更复杂的BLL(对象交互可能很复杂),那么就没有理由说BLL无法与MVC中的M和平共处.

MVC is just a way to organize code, just as BLL or DAL would do. MVC in Rails basically hides DAL altogether by using a set of conventions. Usually business logic resides in the models itself. However, if your application demands more complex BLL where object interactions can be intricate, then there's no reason why that BLL can't peacefully co-exist with the M in MVC.

这篇关于不将MVC架构用于Web应用程序的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 20:45