码迷,mamicode.com
首页 > 移动开发 > 详细

DDD-Mapper

时间:2015-05-15 13:18:15      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

应用层:Application
领域层:Domain Model Layer


为什么要用Mapper,随着技术的变化应用层的DTO会发生变化。大的业务契约不能够保证代码上线一次就成功。需要更换契约,SOA1->SOA2。契约中的长名称变成了短名称。由UserInvoiceItem 变成了  InvoiceTitle  如下




SOA 1.0版本
    [Serializable]
    public class UserInvoiceItem
    {
        public UserInvoiceItem();

        // Summary:
        //     发票ID
        public long InfoID { get; set; }
        //
        // Summary:
        //     发票标题
        public string Title { get; set; }
        //
        // Summary:
        //     Uid
        public string Uid { get; set; }
    }
}


 

SOA 2.0 版本
    // Summary:
    //     常用发票抬头信息
    [Serializable]
    [DebuggerStepThrough]
    [DesignerCategory("code")]
    [GeneratedCode("System.Xml", "4.0.30319.1009")]
    [ProtoContract]
    [XmlRoot(Namespace = "/platform/sps/InvoiceService/v1", IsNullable = false)]
    [XmlType(Namespace = "/platform/sps/InvoiceService/v1")]
    public class InvoiceTitle
    {
        public InvoiceTitle();

        // Summary:
        //     常用发票抬头ID
        [ProtoMember(2)]
        public long inId { get; set; }
        //
        // Summary:
        //     常用发票抬头
        [ProtoMember(3)]
        public string tle { get; set; }
        //
        // Summary:
        //     用户ID
        [ProtoMember(1)]
        public string uid { get; set; }
    }



UserInvoice.Items.Add(Mapper.Map<UserInvoice,UserInvoiceItem>(InvoiceItem));
UserInvoice.Items.Add(Mapper.Map<UserInvoice,InvoiceTitle>(InvoiceItem));

DDD-Mapper

标签:

原文地址:http://www.cnblogs.com/kfsmqoo/p/4505562.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!