模式/策略从创建的DTO的BO [英] Pattern/Strategy for creating BOs from DTOs

查看:116
本文介绍了模式/策略从创建的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屋!

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