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 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义