1

I'm making an MVC website. Here's what I've planned to do earlier:

Data Access Layer
     ^
     |
Business Layer
     ^
     |
Web API 2    <-- Apps or whatever
     ^
     |
MVC5 Website

But I think the following would be a better idea, because since the website and the WebAPI are going to be on the same server in my case, I thought it would make no sense for the website to parse the JSON response of the API.

Data Access Layer
     ^
     |
Business Layer   <--   Web API    <-- Apps or whatever
     ^
     |
MVC5 Website

I am completely new to Web APIs (never done WebAPI or WCF before) and I don't really know what approach to take.

So here are my questions
1. I need a chart (like the ones I've made) representing a better solution with explanation
2. A Project structure for the Visual Studio 2013 Solution that you would recommend

Please note that I have planned to use VS2013's new ASP.NET App project template - not the VS2012 type web templates. Answer keeping this in mind.

A better and descriptive answer is most welcome

galdin
  • 12,411
  • 7
  • 56
  • 71
  • Hi, I believe you can help me with this issue if you have 30 secs... Thks a lot! http://stackoverflow.com/questions/22401403/add-web-api-to-an-existing-mvc-5-web-application – Luis Gouveia Mar 14 '14 at 10:25

2 Answers2

2

To me, this depends on the scope of your application. I've seen a larger corporate system use both an MVC instance alongside a WebAPI with the WebAPI used exclusively for CRUD operations sent as ajax calls from the UI (View's) returned by MVC in a Model-View-ViewModel pattern.

The WebAPI was also consumed by other intranet systems.

So it looked something like this:

MVC  OTHER INTRANET
 |     |
 / \   /
|   \ /
|  WebAPI
|    |
 \  /
  \/
Business
 Layer
   |
   |
Data Access
   |
   DB

This same company also had a separate WebAPI attached to a DAL used as of a home-grown cross company workflow system. As each organizational unit within the company had the same data (domain) model defined, they would physically move (a.k.a SELECT/DELETE from groupA.db.active, INSERT to groupB.db.active, INSERT to groupA.db.INactive with an updated step ID. It worked just fine but I doubt it was the best performing system.

Hope this helps.

1

IMHO definitely do the second, not the first. There is no value having an MVC website call your own Web API.

Darrel Miller
  • 139,164
  • 32
  • 194
  • 243
  • Thanks I'll consider the second, can you make an edit about the VS project templates to use (for MVC and WebAPI) – galdin Nov 24 '13 at 05:19
  • @gldraphael You probably won't like my answer. Templates are a crutch. I don't use them. – Darrel Miller Nov 24 '13 at 20:56
  • okay so what would you suggest I should do. I just want each layer to be in a different project. How should I go about? I just need help with setting up the projects, I'll be able to figure stuff out after that – galdin Nov 25 '13 at 03:40
  • It's been 4 years and I'm all "Darrel answered my question" right now! – galdin Nov 29 '17 at 19:06