将 ASP.Net MVC 转换为 N 层
我最近开始学习 ASP.Net MVC 及其各种功能 MVC_3_MUSIC_STORE + 代码 。
它看起来非常结构化且易于理解。
我正在阅读有关企业应用程序以及它们如何在不同部分分层的内容
(逻辑/物理)
我想知道(用于学习)如何分离(转换)上述 MVC_3_MUSIC_STORE 到 n 层或 3 层应用程序中(因为我们已经有一个工作示例)以便彻底分离关注点。 我在这方面没有太多经验。
需要做出哪些改变?
需要哪些不同的 DTO 或 POCO? 上面的示例使用了从控制器到视图的 POCO 实体。 假设首先使用 EF Code,它会保持不变吗?
我还想知道如果将 WCF Web 服务引入作为数据访问层,需要进行哪些更改。即客户端将向 WCF Web 服务请求数据或从 WCF Web 服务请求数据,而不是从 DAL 检索数据。客户端可以是 Web 应用程序、WinForms 或 Sliverlight 应用程序。
([DAL <--> WCF WS] <--> N CLIENTS)
了解各种方法会很有趣。
示例代码和/或相同的示例会有所帮助。
编辑 1 - 添加
我注意到的一件事是,当我将模型类从模型文件夹移动到新项目“MYMODEL”时,我将不得不在新模型项目中再次添加对“System.ComponentModel.DataAnnotations”和“System.Web.Mvc”的引用?
如何避免这种情况?如何将这些验证转移到业务层?
编辑 2
寻找与此类似的东西 给新手关于 N 层应用程序的建议
I recently started learning about ASP.Net MVC and its various features MVC_3_MUSIC_STORE +
CODE .
It looks very structured and simple to understand.
I was reading about enterprise applications and how they are layered/tiered in different sections
(logical/physical)
I was wondering(for learning ) how to do separate(convert) the above MVC_3_MUSIC_STORE into n-tier or 3 tier application (since we already have a working example) in order to have a clean separation of concerns.
I don't have much prior experience in this.
What changes would be required?
What will be different DTO(s) or POCO(s) that would be needed?
The above example uses POCO entities around from controller to views.
Would it remain same, assuming EF Code first is used.
Also i was wondering what changes will be required if WCF Webservice is introduced as a data access layer. i.e.Instead of retrieving data from DAL ,Clients will request data to and from WCF Webservice. Client can be Web app or WinForms or Sliverlight app.
( [DAL <--> WCF WS] <--> N CLIENTS)
Would be interesting to know about various approaches.
Example code would be helpful and/or examples for same.
Edit 1 - Added
One of the things I noticed was when i move the model classes from Model folder to new project "MYMODEL" I will have to again add reference to "System.ComponentModel.DataAnnotations" and "System.Web.Mvc" in new model project?
How can this be avoided? How can these validations be moved to Business layer?
Edit 2
Looking for something similar to this
Advice For A Newbie About N-Tier Applications
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,唯一需要的更改是您将提供存储库(DAL 层)的实现,它将调用 WCF Web 服务来获取域模型,而不是直接与数据库通信的某些 EF DataContext。更改对控制器和视图完全透明。
Normally the only change that will be required is that you will provide an implementation of the repository (DAL layer) which will call a WCF web service to fetch the domain models from instead of some EF DataContext talking directly to the database. A change completely transparent to Controllers and Views.