Search code examples
entity-framework-4asp.net-mvc-3repository-patternpocoservice-layer

ASP.NET MVC/Service Layer/Repository/EF4/POCO - Am I thinking right?


I have been working on a new ASP.NET MVC application and trying my best to implement the Service Layer/Repository/UOW patter using EF4 and POCO classes.

Help me see if I am understanding this correctly.

Lets say for the sake of keeping this simple, that a client is requesting a view of a Customer.

1) Client requests a view from the CustomerController.
2) The CustomerController creates a new UOW and a new CustomerService passing in the UOW.
3) The CustomerService creates a new Repository(Of Customer) and passes in the UOW it received from the CustomerService. This is the layer where you would say maybe something like "Are you allowed to view this customer?"
4) The CustomerRepository handles getting the POCO classes from the EF4.
5) The CustomerRepository hands the POCO classes back to the CustomerService, which then hands them back to the CustomerController.
6) The CustomerController uses the POCO classes to fill the CustomerViewModel and then hands the CustomerViewModel off to the CustomerView.

I am still a little confused on why/where to use AutoMapper???

Any advice on this would be greatly appreciated.


Solution

  • AutoMapper can be used to "automatically" fill CustomerViewModel from the POCO class instead of manually writing the left side = right side code. However, if you are comfortable with the custom code, there is no need to use AutoMapper. It is just a tool to reduce the custom, boring and error prone code.