哪里的Web API适合在一个典型的N层架构? [英] Where does Web API fit in a typical n-tier architecture?

查看:158
本文介绍了哪里的Web API适合在一个典型的N层架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,当我布局的n层体系结构为一个项目我有以下层次:

Usually when i layout an n-tier architecture for a project I have the following layers:


  • (域模型库合同)

  • 数据(库域模型上工作)

  • 服务(聚合回购,缓存,验证)

  • presentation (MVC的应用程序)

  • Domain (domain model, repository contracts)
  • Data (repositories working on top of domain model)
  • Service (aggregates repos, caching, validation)
  • Presentation (the mvc app)

会在哪里ASP.NET MVC 4的Web API融入这个考虑到它会被实际应用和外部客户端使用?它是在服务层的一部分,或者它使用服务层和与MVC应用程序?

Where would ASP.NET MVC 4 Web API fit into this considering that it will be used by the actual application and outside clients? Is it part of the service layer or does it use the service layer and sits at the same level with the MVC app?

推荐答案

有可能是2的方法:


  1. 您决定从通过HTTP调用MVC应用程序消耗你的Web API。在这种情况下调用code(的HttpClient )坐在您的数据层。无论您是从数据库或远程Web服务获取数据调用它不应该真正的问题。在这种情况下,由于网络API可能已经大​​大封装业务逻辑的服务层将是非常薄的,只是数据访问层周围的包装,甚至是不存在的,如果它不带任何附加的价值。

  1. You decide to consume your Web API from the MVC application through HTTP calls. In this case the calling code (HttpClient) sits in your Data layer. Whether you are fetching your data from a database or a remote web service call it shouldn't really matter. In this case since the Web API probably already encapsulate much of the business logic your service layer will be very thin, just a wrapper around the data access layer, or even non-existent if it doesn't bring any additional value.

由于在Web API是写在.NET中你可以决定直接引用包含此API的服务层装配在你的MVC应用程序。在这种情况下,您的Web API应用程序的服务层成为你的MVC应用程序的服务层。

Since the Web API is written in .NET you could decide to directly reference the assembly containing the service layer of this API in your MVC application. In this case the service layer of your Web API application becomes the service layer of your MVC application.

这篇关于哪里的Web API适合在一个典型的N层架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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