简体   繁体   English

实体,域驱动设计的更新

[英]updates to entity,domain driven design

Lets say I have an order which got updated on the UI with some values (they could be ok/not ok to ensure save) 可以说我有一个已在UI上更新了一些值的订单(为了确保保存,它们可以/不能)
1. How do we validate the changes made? 1.我们如何验证所做的更改? Should the DTO which carries the order back to service layer be validated for completeness? 是否应该验证将订单送回服务层的DTO的完整性?
Once the validation is complete? 验证完成后? How does the service return the validation errors? 服务如何返回验证错误? Do we compose a ReponseDTO object and return it like 我们是否组成一个ReponseDTO对象并像这样返回它

ResponseDTO saveOrder(OrderDTO); ResponseDTO saveOrder(OrderDTO);

  1. How do we update the domain entity order? 我们如何更新域实体顺序? Should the DTO Assembler take care of updating the order entity with the latest changes? DTO汇编器是否应负责使用最新更改来更新订单实体?

If we imagine a typical tiered' approach, ASP .NET on Web Server, WCF on Application Server. 如果我们想象一个典型的分层方法,则是Web服务器上的ASP .NET,应用程序服务器上的WCF。 When the Order form is updated with data on the web and saved. 当订单表单上的数据通过网络更新并保存后。 The WCF receives a OrderDTO. WCF收到OrderDTO。 Now how do we update the order from DTO? 现在,我们如何更新DTO的订单? Do we use an assembler to update the domain object with changes from DTO? 我们是否使用汇编程序通过DTO的更改来更新域对象? something like 就像是

class OrderDTOAssembler {
 updateDomainObject(Order, OrderDTO)
}

I will try answer some of your questions from my experience and how I should approach your problem. 我将尝试根据我的经验回答您的一些问题,以及如何处理您的问题。

First I should not let DTO conduct any validations, but just plain POCO DTO's usually have different properties with specific datatypes, so some kind of validation is done. 首先,我不应该让DTO进行任何验证,而只是普通的POCO DTO通常具有针对特定数据类型的不同属性,因此需要进行某种验证。 I mean you have to apply an integer street number and string for street name etc. 我的意思是您必须为街道名称等应用整数街道编号和字符串。

Second as you point out. 正如您所指出的那样。 Let a ORderDTOAssembler convert from OrderDTO to Order and vice versa. 让ORderDTOAssembler从OrderDTO转换为Order,反之亦然。 This is done in the application layer. 这是在应用程序层中完成的。

Third I would use Visitor pattern Validation in a Domain Driven Design like the example. 第三,像示例一样,我将在域驱动设计中使用访客模式验证 The OrderService will use an IOrderRepository to save/update the order. OrderService将使用IOrderRepository来保存/更新订单。 But using the visitor-validation approach the OrderService vill call Order.ValidatePersistance (see link in example - but this is a extension method that is implemented in infrastructure layer since it has "db knowledge") to check its state is valid. 但是使用访问者验证方法,OrderService会调用Order.ValidatePersistance(请参见示例中的链接-但这是在基础结构层中实现的扩展方法,因为它具有“数据库知识”)以检查其状态是否有效。 If true, then we to IOrderRepository.Save(order). 如果为true,则我们将IOrderRepository.Save(order)。

at last, if Order.ValidatePersistance fails we get one or more BrokenRules messages. 最后,如果Order.ValidatePersistance失败,我们将收到一个或多个BrokenRules消息。 These should be returned to client in a ResponseDTO. 这些应在ResponseDTO中返回给客户端。 Then cient can act on messages and take action. 然后,科学家可以根据消息采取行动并采取行动。 Problem here can be that you will have a ResponseOrderDTO messages but maybe (just came up with this now) all your ResponseDTO can inherit from ResponseBaseDTO class that expose necessary properties for delivering BrokenRule messages. 这里的问题可能是您将有一个ResponseOrderDTO消息,但是(现在才想出)所有您的ResponseDTO都可以继承自ResponseBaseDTO类,该类暴露了传递BrokenRule消息所需的属性。

I hope you find my thoughts useful and good luck. 希望您发现我的想法有用并且祝您好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM