1

I'm starting a project with MVC 2 and would like to know if the following structure 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.

1 Answer 1

3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.