mercredi 4 mars 2015

Code resuse in an unified ASp.NET MVC and WebAPI application

I'm building a web application using ASP.NET MVC that needs to be accessible via a web browser (via Views), as well as from mobile applications via Web API. The thing is that I would like to avoid duplicating business logic in controllers for Views (inherited from Controller) and controllers for Web API (inherited from ApiController).


Basically I would like to go with a design where the web application is simply using the Web API, and all the business logic is implemented in the Web API.


View <-> Controller <-> Web API Controller <-> Data Model


What is the best way to design such an application? Is there a simple way to call Web API controllers from the same MVC application? Or is it better to go with two separate applications/projects?





Aucun commentaire:

Enregistrer un commentaire