Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have seen in the application I have just started working that Web API controllers are added to MVC UI project and there is no separate Web API project created for the application.

What I have tried:

When I asked architect of the application about this, he just answered that it was already built in application and thus he did not modify the architecture. 
I did not get the actual reason for this architectural style of having Web API controller in MVC UI Project.

Please someone can explain me the advantage of it and if it is a good practice to follow this.
Posted
Updated 21-Aug-18 17:45pm
Comments
Richard MacCutchan 21-Aug-18 10:44am    
You could try the MVC documentation.

1 solution

Knowing nothing about your project, I'll give you my view.

While what your coworker said is correct, web api controllers are included as part of the MVC project (in terms of functionality, MVC controllers and web api controllers are very similar)...your coworker might be using them interchangeably without realizing or possibly just doesn't care since they serve the same purpose.


I'd bet a lot of money if you went in there and changed all of the web api inherited controllers from ApiController (Ex: MyWebApiController : ApiController) to Controller (turning them from web api to mvc controllers) it would probably still work the same. There may be differences if your doing file uploads or other things but simple/basic crud commands would likely see no issue.

So the point, does it really matter? Probably not but thats making a lot of assumptions about a project I have never seen. Is there advantages? If its a simple standalone project that is only the web UI, the only advantage I can see is only one project/solution to deal with (to me this isn't a big deal anyways).

As for this being a good practice, If you were building an app that would have multiple UI's (think web, desktop, mobile) I probably wouldn't tightly couple the web UI project with the API layer like what has been done, i'd split that out into separate projects and introduce the API as its own project and the MVC as its own project.

It may be too far down the dev path that attempting to split this apart is just considered technical debt at this point for you but I doubt using web api controllers in an mvc project is doing any harm.
 
Share this answer
 
Comments
RohitVaidya 22-Aug-18 2:57am    
Thanks David for the detailed explanation of my query.

Yes its a standalone application so having Web API in single project cause no harm.

However if it works same even after changing all web api inherited controllers from API Controller to normal controller then I think it makes no sense to me writing Web API controller instead of normal controller.

Generally the main purpose of writing web api is to provide service interface to different applications and here in my example we are not serving that. :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900