[英]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應用程序結構。
以便能夠通過Intranet在不同的服務器上運行應用程序的不同部分。
輕松更新其中一個層,而無需重寫其他層。
如果構建正確,則允許您構建應用程序的附件。
至於靈活性,我發現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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.