在 POCO 中使用 AutoMapper?
目前,我的 ASP.NET MVC 项目中有一个 POCO 类来处理所有业务逻辑。没有引用其他项目或第三方程序集。
我还在其他项目中使用 AutoMapper 来促进视图模型/实体之间的映射。这是一个很棒的工具,当我更改给定实体上的字段时,它可以为我节省大量时间。
然而,在我的 POCO 类中,有一些在实体之间映射的代码段。业务目的是从一个数据源获取实体并更新另一个数据源。在这里,我手动映射,当我可以使用 AutoMapper 时,我发现进入并调整该映射很烦人。
在我的业务逻辑项目中使用 AutoMapper 是好主意还是坏主意?为什么?
I currently have a POCO class in my ASP.NET MVC project that handles all business logic. There are no references to other projects or third-party assemblies.
I am also using AutoMapper in my other projects to facilitate mapping between view models / entities. It is a fantastic tool and saves me considerable time when I make changes to fields on a given entity.
However, within my POCO class are a few segments of code that map between entities. The business purpose is to take entities from one data source and update another data source. Here I am manually mapping and I'm finding it annoying to go in and adjust that mapping when I could employ AutoMapper instead.
Is it a good idea or a bad idea to use AutoMapper in my business logic project? Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会用一个问题来回答你的问题。
为什么使用 AutoMapper 映射属性会很糟糕?除了担心获取外部程序集引用之外,我想不出您不想使用 AutoMapper 的原因。
'll respond to your question with a question.
Why would it ever be bad to use AutoMapper to map properties? I cannot think of a reason, besides a concern over taking an external assembly reference, that you would not want to use AutoMapper.