punkouter
punkouter

Reputation: 5356

How to seperate ASP.NET MVC core view and ASP.NET WEB API controllers into separate projects?

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 ?

Upvotes: 1

Views: 1350

Answers (1)

Jon Ryan
Jon Ryan

Reputation: 1627

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.

Upvotes: 5

Related Questions