What are the pros and cons of having a WebAPI in the same or different project [closed]

孤街醉人 提交于 2020-01-06 13:09:33

问题


I have an MVC application and the solution consist of three project as described below:

Store.Domain : Holds the domain entities and logic (repositories created with the Entity Framework).

Store.WebUI : Holds the controllers and views; acts as the UI for the application.

Store.UnitTests : Holds the unit tests for the other two projects.

I will use WebAPI 2 in my application in order to create web services for some of the Android applications. Now I am not sure about the issues below:

1) By keeping in mind security and maintenance concerns, should I create a separate project for WebAPI or use WebAPI in the Store.WebUI project? As I will also install WebAPI documentation nuget and it will create several folders and files in the project, I think creating a new project maybe better.

2) Assuming to create a new project dedicating for WebAPI, what would be the project type and choices for the WebAPI project? Is it true the following selections as indicated on the screenshot?

Project Type: ASP.NET Web Application
Project Template: Just select Web API

Thanks in advance.


回答1:


WebApi is an alternative Service oriented application from Microsoft just like WCF. But WCF uses SOAP protocol and WebAPI uses HTTP protocol for communication.

So if you are using WEBAPI to provide service for your MVC application you would host that WEB API service seperately and consume its service by MVC application,

If you want them (MVC and WebAPI) to use in the same project, follow this rules from this article.

Hope that helps.



来源:https://stackoverflow.com/questions/30330403/what-are-the-pros-and-cons-of-having-a-webapi-in-the-same-or-different-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!