ASP.NET MVC Application Design
Ok, So I have been taking in all sorts of gre开发者_如何学Pythonat information about MVC, EF4, Repository Pattern, UoW, Service Layers, etc and now I am going to attempt to put it all together.
My question is, How should these be separated?
I was thinking projects like this:
1) Application - MVC App
2) Repository Layer 3) Entities - EF4/Partial Entity ClassesAny suggestions would be great!!
Thanks, Sam
Here's one example of how you could structure your application:
- Domain Models (Primary POCO objects)
- Repositories (Implementation of some data access technology depending on the project requirements : EF, NHibernate, LINQ to XML, Remote web service calls, ...)
- Service (business operations aggregating multiple CRUD operations into a business operation that will be exposed with the domain objects)
- ASP.NET MVC application (Controllers, Views, View Models, Mappers between the Domain objects and the view models)
This layers could represent a physical separation (assemblies) or logical separation into the same assembly.
Don't separate code physically until you have a physical reason to do so such as deployment or code sharing reasons. Use folders and namespaces.
I've just been through this myself and by far the best approach i found is S#arp Architecture.
Excellent templates generate the project scaffolding for you and they have a good explanation why u really do want physical project separation. Good argument here. Theyre tutorial shows how TDD with this model is a breeze.
The beauty of this model is the separation of concerns it offers so if you did want to use EF, its a snip to swap out NHibernate.
精彩评论