1

Right now the API and MVC controllers are in same project and that is fine. Later I will add a Angular frontend. But since the angular front end is a separate project wouldn't it make sense for the ASP.NET core MVC views to be a separate project? Any links anywhere how to do this ? I imagine this way the 2 view (Angular and ASP.NET core MVC) would both call the WEB API layer and that seems more logical. ..

Or if they stayed in the same project I should atleast have the MVC controller call the WEB API controller? Or no ?

1 Answer 1

5

If I understand correctly...

You have a MVC application which also has some API controllers in it. You are adding an angular project which needs to call the API controllers and you are wondering if you should move the API controllers into a separate project?

If so then.... probably.

In doing so the API would become your central source of business logic and the MVC app and Angular app two different presentations of that central logic.

But ultimately it's an architectural decision which you need to make based on how you see the solution moving forward.

So if it helps:

  • Reduce complexity
  • Helps the code follow the SOLID principles
  • Stops you from breaking the DRY principle
  • Allows for better separation of concerns
  • The time and cost to do so is acceptable

Then go for it.

You may find that the MVC project and API project have shared dependencies. So you may end up having to move things like Models or Entities into their own projects too so both can reference them. You may also need to think about authentication and how that will work and consider something like identity server.

Hope that helps.

Sign up to request clarification or add additional context in comments.

3 Comments

But does it ever make sense for the MVC project to just reference the WEB API project (both are web projects) to get the data? It seems like it would but I have never seen it done that way and not so how I would call the WEB API controllers from the MVC controllers
My end goal is make the MVC layer as thin as possible and just another front end in the same way angular.. or blazor would be a front end
To call the API Project from the MVC project you can use the http client: tutorialsteacher.com/webapi/… c-sharpcorner.com/article/calling-web-api-using-httpclient You can probably create a wraper for the http client code so you don't write the same code over and over again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.