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

查看:109
本文介绍了什么是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.)

的WebAPI MVC4 出现如此大的吸引力,因为我们将能够从其他应用程序调用的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.

推荐答案

我做的是这样的:


  • 库查询数据库

    • 服务层验证的东西,以避免code复制

      • 的Web UI

      • 的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天全站免登陆