MVC4 WebAPI 的正确架构是什么 [英] What is the correct architecture for MVC4 WebAPI

查看:34
本文介绍了MVC4 WebAPI 的正确架构是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行了一些搜索,但没有找到此问题的可用答案.

I ran some searches but found no available answer to this issue.

好吧,我的 MVC 3 架构是这样的:

Okay, my MVC 3 architecture is like this:

- Project.EDM (contains only the entity framework edmx file and its .tt and .cs entity classes)
- Project.DAL (contains IXxxRepositiory and XxxRepository where CRUD is performed on the entity classes)
- Project.Web (the MVC3 project. Controllers transfer data from ViewModels into entity models and call the CRUD functions in the DAL repositories.)

MVC4 中的 WebApi 看起来很有吸引力,因为我们将能够从其他应用程序调用 CRUD 操作.我们都喜欢这个主意.

The WebApi in MVC4 appears so attractive since we will be able to call the CRUD operations from other applications. We all love this idea.

但是我发现的现有示例在 ApiController 下的 MVC4 项目中具有 CRUD 操作.我习惯将这些操作放到一个单独的 DAL 项目中.推荐的选择是什么?我们还能有一个单独的 DAL 类吗?你们专家是如何设计架构的?

But the existing examples I have found have the CRUD operations inside the MVC4 project under ApiController. I am used to putting these operations into a separate DAL project. What is the recommended choice? Can we still have a separate DAL class? How do you experts design the architecture?

感谢您提供所有有用的建议.

Thank you for all helpful advice.

推荐答案

我要做的是:

  • 用于查询数据库的存储库
    • 用于验证内容并避免代码重复的服务层
      • 网页界面
      • Web API

      因此 UI 和 API 都将拥有一个或多个服务,而这些服务又拥有一个或多个存储库对象.

      So both the UI and the API will have one or multiple services, that in turn have one or multiple repository objects.

      大多数示例直接从 ApiController 查询数据库的唯一原因可能是因为简单.

      The only reason why most examples directly query the database from the ApiController is probably because of simplicity.

      这篇关于MVC4 WebAPI 的正确架构是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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