我一直在开发一个新的 ASP.NET MVC 应用程序,并尽力使用 EF4 和 POCO 类来实现服务层/存储库/UOW 模式。
帮我看看我是否理解正确。
为了保持简单起见,假设客户正在请求客户的视图。
1) 客户端向 CustomerController 请求视图。
2) CustomerController 创建一个新的 UOW 和一个传入 UOW 的新 CustomerService。
3) CustomerService 创建一个新的 Repository(Of Customer) 并传递从 CustomerService 收到的 UOW 。在这一层,您可能会说“您可以查看该客户吗?”
4) CustomerRepository 处理从 EF4 获取 POCO 类。
5) CustomerRepository 将 POCO 类返回给 CustomerService,然后将它们返回给 CustomerController。
6) CustomerController 使用 POCO 类来填充 CustomerViewModel,然后将 CustomerViewModel 交给 POCO 类。 >客户视图。
我仍然对为什么/在哪里使用 AutoMapper 有点困惑???
对此的任何建议将不胜感激。
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.
发布评论
评论(2)
AutoMapper可用于从POCO类“自动”填充CustomerViewModel,而不是手动编写左侧=右侧代码。但是,如果您对自定义代码感到满意,则无需使用 AutoMapper。它只是一个减少定制、无聊和容易出错的代码的工具。
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.
Automapper是由工具自动生成的,可以放入DAL中。如果我们想替换实体框架本身,那么我认为我们可以重用自动映射器类。
类似的尝试可以在 GitHub
TechNet
The Automapper is generated automatically by the tool and can be put in the DAL. Incase we want to replace Entity Framework itself, then in my opinion we could reuse the automapper classes.
Similar is attempted and can be found in the GitHub
TechNet