服务层的AutoMapper
我有一个 MVC 项目,我在其中使用 AutoMapper 将实体框架实体映射到视图模型。定义映射的代码位于应用程序启动时自动调用的 boostrapper 类中(App_Start、Global.asax)
我正在对代码进行一些重构,以将所有业务逻辑放入服务层中,因为我们需要实现每天运行的批处理进程,它执行与 MVC 应用程序相同的逻辑。
我遇到的问题之一是现在我需要将数据库实体映射到服务层中的某些域对象。我认为 MVC 应用程序中的一切仍然可以正常工作,因为引导程序仍在 Global.asax 中被调用。
有没有办法让我的映射代码同时适用于我的 MVC 应用程序和另一个非 MVC 应用程序(可能是 WCF 服务、控制台应用程序等)?我可以在哪里放置此映射代码,以便两个应用程序都调用它只有一次吗?
I have an MVC project where I am using AutoMapper to map my Entity Framework Entities to View Models. The code that defines the mappings is in a boostrapper class that is called automatically when the application starts (App_Start, Global.asax)
I am doing some refactoring of my code to put all of my business logic in a Service Layer because we need to implement a batch process that runs daily which is doing some of the same logic as the MVC app.
One of the problems I am running into is now I need to map my database entities to some domain objects in my service layer. I think everything would still work fine in the MVC application because the bootstrapper is still being called in Global.asax.
Is there a way I can have my mapping code work for both my MVC application and another non-MVC application (could be a WCF service, console app, etc.) Where can I put this mapping code so it would get called by both applications only once?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是静态类,可用于WCF服务初始化:
Here is static class, could be used for WCF services initialization:
为什么不直接将 global.asax 文件添加到您的服务项目中呢?
将您的映射放入一个新项目中,在两个项目中进行引用,然后就完成了。
Why not just add a global.asax file into your services project?
Throw your mappings into a new project, reference in both, and you are done.