5

Microsoft recently released MVC 4 Beta, which has these new very nice features like Web API and SPA. And as always Microsoft's demos do not demonstrate best practices from software design prospective. For example, using DbController which is tightly coupled to EF.

It seems for me that SPA and Web API go hand-by-hand in modern ASP .NET app. I would like to hear any suggestions about structuring MVC 4-based solution, which is going to apply these new technologies like Web API and SPA.

For example, is it a good practice to separate Web API project with it's own controllers out of base MVC4 project or not. How to deal with SPA and not to use DbController in order to keep data persistence separately? What's going to be a main role of regular MVC4 app and especially Razor views?

Any other thoughts or suggestions are highly appreciated.

Community
  • 1
  • 1
Alex
  • 389
  • 1
  • 3
  • 8

2 Answers2

4

On separation of MVC4 + Web API: imho (as always) it depends on your concrete project.

Regarding EF: you should definitely not return EF Entities but return your own DTOs instead.

The role of MVC razor views could be rendering partial views you dynamically load from the client. You also could do some stuff like conditional loading of CSS / JS etc. for the Index page being loaded initially.

Alexander Zeitler
  • 11,919
  • 11
  • 81
  • 124
3

I think it's a good idea to keep the API in a separate web site project from your SPA/web site, as you can run in to problems with greedy routes.

Definitely keep your data access separate and loosely coupled.

Antony Scott
  • 21,690
  • 12
  • 62
  • 94