应用层: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));
时间: 2024-10-06 18:30:49