开发者

EF + Automapper, is this a good approach to a ASP.NET MVC 2 web app project?

I'm starting a project with MVC 2 and would like to know if the following struct开发者_开发百科ure is a good approach in terms of design.

Currently I have divided my web app in two projects

-ApplicationModelLayer (library project)

  • Models

Here I have one class for each entity of my database where I'll write validations and business logic. When I do CRUD operations, I call Automapper to do the mapping: MyModelClass -> EFClass.

-ApplicationViewLayer (MVC 2 web project)

  • Controllers
  • Views

Am I applying a good design and separation of the ApplicationModelLayer ? Is this "better" than using just EF with partial classes to do the validation?

Thank you.


I would put the view model classes and the mappings between the EF models and the view models inside the ApplicationViewLayer. Because view models are specifically designed for the requirements of a view I would use the Models folder of the web application to store them.

As far as the model layer is concerned, in the addition to the Models folder, I would have a Repositories and Services folders. The Repositories is for CRUD operations with the EF domain models and Services should contain the business logic and more complex operations with the domain models based on the simple CRUD operations.

In the web tier a controller action will consume a service operation to fetch a domain model, map this domain model using AutoMapper to a view model and pass the view model to the view. And the other way round: a controller action could receive a view model from the view, use AutoMapper to map it back to a domain model and pass this model to the service layer for processing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜