Microsoft ASP .NET Web API, MVC 4 and SPA Architecture
Asked Answered
S

2

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.

Shaeffer answered 10/3, 2012 at 1:42 Comment(0)
E
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.

Earvin answered 10/3, 2012 at 12:52 Comment(0)
S
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.

Stool answered 10/3, 2012 at 19:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.