从DTO创建BO的模式/策略 [英] Pattern/Strategy for creating BOs from DTOs
本文介绍了从DTO创建BO的模式/策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我喜欢拥有定义我的服务器接口的属性包对象(DTO)的方法,但我不喜欢这样编写代码:
I like the approach of having property bag objects (DTOs) which define the interface to my server, but I don't like writing code like this:
void ModifyDataSomeWay(WibbleDTO wibbleDTO)
{
WibbleBOWithMethods wibbleBO = new WibbleBOWithMethods();
wibbleBO.Val1 = wibbleDTO.Val1;
wibbleBO.Val2 = wibbleDTO.Val2;
}
这个复制代码写得很辛苦。如果复制代码是不可避免的,那么你放在哪里?在BO?在工厂?如果可以手动避免编写锅炉板代码,那么如何?
This copying code is quite laborious to write. If the copying code is unavoidable, then where do you put it? In the BO? In a factory? If it is possible to manually avoid writing the boiler plate code then how?
提前感谢。
推荐答案
看起来像 AutoMapper 的工作,或者(简单)只需添加一些接口。
That looks like a job for AutoMapper, or (simpler) just add some interfaces.
这篇关于从DTO创建BO的模式/策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文