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?