Where does Web API fit in a typical n-tier architecture?

社会主义新天地 提交于 2019-11-30 02:04:11

There could be 2 approaches:

  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.

  2. 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.

There are two possibilities

  • Middle-tier or middleware: this is where typically web services and WCF Services have been working. Using REST is much lighter than SOAP so this is de-facto use case. Web and WCF services are better in respect to client generation but Web API will gradually catch up.
  • Presentation layer: this will provide data to the Single-Page-Applications or any modern web site/application that uses data and renders on the client.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!