0

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.

enter image description here

Jack
  • 1
  • 21
  • 118
  • 236
  • 2
    Question asking "which should I do" or "whats better" are very opinion based and typically don't facilitate helping with hard facts. I would suggest asking *what are the pros and cons of having a webapi in the same project or a different project*. – Erik Philips May 19 '15 at 15:54
  • The screen itself is pretty self explanatory... `Select a template`, and `Add folders and core references for:` do exactly what they suggest. The description to the right tells you what is in the template you select. An `Empty` template with `Web API` references is possible. – Claies May 19 '15 at 16:00
  • I am asking to use it or not? What I meant to create a new project ot not. If I will continue my current project, how can the screen tells me the right??? Could you please re-read the question? – Jack May 19 '15 at 16:02
  • you are essentially asking "if you were me and developing this project, which one of these would you choose?" Which is a matter of opinion, and not on topic for the site. – Claies May 19 '15 at 16:04
  • @Claies Why? Can people at here ask for their opinions and get their suggestions? such a kind of problems? Or in order to ask a question, do I have to an error coming from Visual Studio, or web browser? I know there are more ways than one to solve a problem and all of them can be true. But at here I emphasizes **keeping in mind security and maintenance concerns** when asking the question. You might have an idea for this issue? Do not you? – Jack May 19 '15 at 16:11
  • which project template to select doesn't have any bearing on security and maintenance concerns. any template can be used for any kind of project, they are merely a starting point. – Claies May 19 '15 at 16:16
  • **By keeping in mind security and maintenance concerns, should I create a separate project for WebAPI or use WebAPI in the Store.WebUI project?** – Jack May 19 '15 at 16:18
  • Again, this is really not something that we can answer. Are you wanting a different URL for your API users so that your web users can't modify the data? are you worried about how hard it will be to maintain two different sites for UI and API? do you need SSL support for one and not the other? do you need CORS support? This is entirely subjective, and project domain dependent. What is right for one project may not be right for a different project. – Claies May 19 '15 at 16:24
  • Actually you have given most of the possible issues I will face regarding to this issue. So, by keeping in mind all of them, what would you suggest? [Here](http://stackoverflow.com/questions/15494920/what-is-the-difference-between-dependencyresolver-setresolver-and-httpconfigurat/15495934#15495934) is an answer giving suggestion that you have not managed yet. Have a look at Steven's answer, maybe it is helpful for you... – Jack May 19 '15 at 16:55

1 Answers1

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.

moyomeh
  • 155
  • 3
  • 14
  • Thanks for reply. Actually I have a look at the same article today, but it did not give a definite answer. So, I understand from your answer that you suggest to create a new separate project for WebAPI? Is that true? If so, ahoıuld the Project Type be **ASP.NET Web Application** and Project Template be **Web API**? – Jack May 19 '15 at 16:21
  • Yes for the project template – moyomeh May 19 '15 at 16:24
  • I asked 2 question in my last comment. I am not sure to which one you answered. On the other hand, will I also set the WebAPI project as **Setup project** besides the WebUI project? Could you answer all of three questions? – Jack May 19 '15 at 17:25
  • 2/ Yes for the Project Type to be ASP.NET Web Application and Project Template be Web API. – moyomeh May 20 '15 at 08:58
  • Thanks :) Voted+. What about the last question regarding to startup project? – Jack May 20 '15 at 09:45
  • 1
    Right click in your solution, choose properties and then startup project. select "multiple startup project" and then select your mvc and webapi project – moyomeh May 20 '15 at 12:51