自动映射器和不变性 [英] Automapper and immutability

查看:80
本文介绍了自动映射器和不变性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将AutoMapper与不可变类型一起使用?

Is it possible to use AutoMapper with Immutable types?

例如,我的域类型是不可变的,我想将视图类型映射到该域.

For example my Domain type is immutable and I want to map my view type to this.

我相信不是,只是希望得到证实.

I believe it is not but just want this confirmed.

将域类型设为不可变也是一种最佳做法,将视图类型映射到域类型时的最佳做法是什么?

Also as it is best practice to have your domain types immutable, what is the best practice when mapping your view types to domain types?

推荐答案

我通常会手动执行从视图类型到域类型的映射,因为我通常会使用方法等通过更复杂的界面进行操作.如果您使用AutoMapper从视图转到域,则无论是否有意决定,现在都将锁定在贫血的域模型中.

I typically do the mapping from view types to domain types by hand, as I'll typically be working through a more complex interface, using methods and so on. If you use AutoMapper to go from view to domain, you're now locked in to an anemic domain model, whether you've intentionally decided to or not.

这篇关于自动映射器和不变性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆