Reputation: 1510
I've been using ASP.Net MVC (with Razor syntax) successfully for over a year now and wanting to move to Web API.
With MVC I'd usually set my n-tier architecture up as follows (simplified for ease of explanation):
What I am starting to dislike about this is that there seems to be a lot going on in the Presenation layer; you've got models, razor views, controllers plus any added niceties such as javascript / AngularJS & CSS.
How would you recommend I set up my tiers when using Web API instead of MVC? Is it the same as above but with an added layer? Something like this:
Or are all the HTML pages to be put in the same project as the Web API? This seems odd to me as I feel like you need to keep your API separate from all other concerns such as the User Interface.
Any insight will be gratefully received.
Upvotes: 3
Views: 2365
Reputation: 2381
I'm working along those lines these days. Web API as a gateway for data from and to the application, and HTML completely independent. Now here you got two choices
That on the front-end side, as for the backend the Web API layer is what in older applications would have been a WCF application, so the Web API controlles is what the .svc file implementation was, and from there you'd have a class library for business logic, one for data access (SQL / ORM) and finally another for domain objects (shared across web api, business and data layers).
Thats how I tend to structure things whenever I can. For using HTML with Web API, I tend to like option 2, mostly because is easily integrated with VS, and if you really need anything from Razor you have it handy. And mostly because that way you work with the structure Visual Studio favors and not against it (and in the long run its easier to go along with it)
Hope that helps
Upvotes: 1