如何构建企业MVC应用程序,业务逻辑去向何方? [英] How to structure an enterprise MVC app, and where does Business Logic go?

查看:34
本文介绍了如何构建企业MVC应用程序,业务逻辑去向何方?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 MVC 新手.据我所知:

I am an MVC newbie. As far as I can tell:

  • 控制器:处理路由请求
  • 查看:处理数据的呈现
  • 模型:看起来很像数据访问层
  • Controller: deals with routing requests
  • View: deals with presentation of data
  • Model: looks a whole lot like a Data Access layer

业务逻辑去哪里了?

采用大型企业应用程序:

Take a large enterprise application with:

  • 多个不同的数据源(WCF、WebServices 和 ADO)在数据访问层中捆绑在一起(使用多个不同的 DTO).
  • 在多个 dll 上分割了很多业务逻辑.

MVC Web 应用程序位于此之上的合适方式是什么(在代码和项目结构方面)?

What is an appropriate way for an MVC web application to sit on top of this (in terms of code and project structure)?

我看到的示例中,所有东西都放在 Model 文件夹中,它们似乎不适合非常大的应用程序.

The example I have seen where everything just goes in the Model folder don't seem like they are appropriate for very large applications.

感谢您的建议!

推荐答案

在我的应用程序中,我通常会创建一个与 Web 项目分开的核心"项目.

In my apps, I usually create a "Core" project separate from the web project.

核心项目包含:

  1. 业务对象,例如实体等
  2. 数据访问
  3. 任何不是专门为网络设计的
  1. Business objects, such as entities and such
  2. Data access
  3. Anything that is not specifically designed for web

Web 项目包含:

  1. 控制器,将请求从 UI 路由到核心逻辑
  2. Views,专注于在 HTML 中呈现数据
  3. 视图模型,将核心业务对象扁平化/转换为旨在支持特定视图的更简单的结构
  1. Controllers, which route requests from the UI to the core logic
  2. Views, which focus on presenting data in HTML
  3. View Models, which flatten/transform core business objects into simpler structures designed to support specific views

这里的关键点是基于 Web 的 Models 文件夹/命名空间仅用于特定于演示文稿的模型,这些模型记录了给定视图所需的特定变量.尽可能多的业务逻辑"进入核心项目.

The key point here is that the web-based Models folder/namespace is ONLY used for presentation-specific models that document the specific variables needed for a given view. As much "business logic" as possible goes into the core project.

这篇关于如何构建企业MVC应用程序,业务逻辑去向何方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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