doulu6234 2017-09-19 12:55
浏览 140
已采纳

如何使用DTO处理与命令总线方法的关系

In a new greenfield project I'm using a command bus approach, problem I'm encountering is how I should handle relationships.

For example, an Order has multiple OrderLines, a Shipping and Invoice address.

Since I'm using a command bus approach I want to pass a DTO to my command bus holding all the information necessary to create an Order.

Should this command also hold relationships (i.e. an CreateOrderTask, CreateOrderAddress)?

My directory/file structure looks like this:

- Infrastructure
-- Ui
--- Web
---- CreateOrderController.php
-- ....
- Application
-- CreateOrder
--- CreateOrder.php
--- CreateOrderHandler.php
--- CreateOrderLine.php (?)
- Domain
-- Order
--- Order.php
--- OrderLine.php
--- Address.php
-- ...

So should the CreateOrder class look like this:

// CreateOrder.php

<?php

class CreateOrder {

    /** @var CreateOrderLine[] */
    protected $createOrderLines;

    public function __construct(array $createOrderLines) 
    {
        $this->createOrderLines = $createOrderLines;
    }

    public function getCreateOrderLines()
    {
        return $this->createOrderLines;
    }
}

Although I think there are many correct answers, I'm looking for a best practice. What are your thoughts?

  • 写回答

2条回答 默认 最新

  • dongyan2445 2017-09-19 13:36
    关注

    It depends on your transaction boundaries.

    If you need that all the commands must succeed or fail together then you in fact must have a bigger command with all the data needed.

    If any of the sub-commands fails and the system is still in valid state then you don't need a bigger command and you may send multiple commands in some kind of batch, each one having its own transaction boundary.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料