繁体   English   中英

将ASP.NET MVC标准应用程序转换为N层应用程序

[英]Converting ASP.NET MVC Standard application into N-Tier Application

我正在开发一个正在使用ASP.NET MVC的应用程序。 然后,我了解了n层体系结构,认为它为应用程序提供了更大的灵活性,因此我开始将我的标准mvc项目转换为n层 我也有基于角色的观点。 在问这个问题之前,我已经阅读了很多有关N层体系结构的在线文章,但是每个人都有它自己的n层结构。 我没有找到任何显示N-Tier应用程序标准化结构的示例。 我的应用程序的MVC结构如下:

Models :
- IBaseEntity
- IDeletableEntity
- IValidatableEntity
- File : IBaseEntity, IDeletableEntity, IvalidatableEntity
- User : IBaseEntitiy
Repositories :
- IRepo <T> where T : IBaseEntity
- IDeletableRepo <T> where T : IDeletableEntity
- IValidatableRepo <T> where T : IValidatableRepo
- Repo <T>: IRepo <T> where T : IBaseEntity
- DeletableRepo <T>: IDeletableRepo <T> where T : IDeletableEntity
- ValidatableRepo <T> : IValidatableRepo<T>where T : IValidatableRepo
- UnityOfWork //encapsulating all repos and providing acces to them
Services :
- IService <T>: where T : IBasEntity
- IValidatableService <T> where T : IValidatableEntity
- Service <T> : IService <T> : where T : IBasEntity
- ValidatableService <T>: IValidatableService <T> where T : IValidatableEntity

Controllers:
- FileController : Controller
- UserController : Controller

Views:
  File :
  - index.cshtml
  - view.cshtml
    Admin :
    - view.cshtml //Admin has more option while viewing page)
  User :
  - Profile.cshtml
    Admin :
    - AllProfile.cshtml

为了将其转换为N-Tier,我开始阅读许多在线文章,但我仍然感到困惑。 但是我实现了n层,其结构如下:

Project Solution

 Project.BusinessObject
    Models

 Project.BusinessLogic
    Services

 Project.DataAccess
   Repositories

 Project.InversionOfControl
   Autofac

 Project.UserInterface
   Controllers
   ViewModels
   Views


我的n层应用程序的流程是: 控制器->服务->仓库+ AutoFac->模型
实际上,我想发布一张图片,但是我无法使用10个Stackoverflow信誉标准。
您可以单击此处查看我的应用程序的n层结构
由于这是我对n层体系结构的第一次体验,因此我不确定该应用程序的结构是否良好。 如果有人可以告诉我我做错的要点或需要进行某种修改的要点,那将是非常有用的帮助。

Some other questions if you could help me out :
Business object is same as a model ?
Business logics are methods for a business object ?

我出于以下原因而喜欢分层应用程序方法。 MVC体系结构是分层的应用程序。 这意味着您的应用程序具有:

表示层,视图

应用程序处理层,控制器和

数据管理层,模型。

大多数开发人员出于一些不同的原因而使用N-Tier应用程序结构。

  1. 以便能够通过Intranet在不同的服务器上运行应用程序的不同部分。

  2. 轻松更新其中一个层,而无需重写其他层。

  3. 如果构建正确,则允许您构建应用程序的附件。

至于灵活性,我发现n层的灵活性可能不是那么灵活,其想法是正确地分离您的层并将所有内容注入到其他层,如果您不熟悉创建这样的应用程序,这可能是一件非常麻烦的工作。 如果您希望将数据与应用程序分开,则可以将数据层设置为Web服务。 这样,您的MVC应用程序将能够访问它,移动应用程序,桌面应用程序或您希望编写的任何其他应用程序也将能够访问它。

无论如何,多层主要是关于将应用程序扩展到多台机器,因为灵活性方面,我不确定除了我列出的内容以外,您对N层可以做的任何事情都无法对MVC结构进行。

有一个很好的n层体系结构的好例子,这里有一些链接。

http://www.codeproject.com/Articles/70061/Architecture-Guide-ASP-NET-MVC-Framework-N-tier-En

https://visualstudiogallery.msdn.microsoft.com/74633fdf-0563-4c75-aca8-f69835e7f8ab

http://www.orchardproject.net/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM