Currently the dependency tree of the consumer is a bit vague. Consumer requires a command bus. The problem is that when an event middleware is passed to the command bus and one of the listeners is used, the listener requires the consumer. This circular-like dependency is bad.
The proposed solution:
use League\Tactician\Bernard\Consumer;
use League\Tactician\CommandBus;
use League\Tactician\CommandEvents\EventMiddleware;
use League\Tactician\CommandEvents\Event\CommandLimit;
$consumer = new Consumer();
$eventMiddleware = new EventMiddleware();
$eventMiddleware->addListener(new CommandLimit($consumer, 1));
$commandBus = new CommandBus([$eventMiddleware]);
$consumer->consume($queue, $commandBus);
This way the tree becomes linear as the command bus can be the last initiated class:
Currently the dependency tree of the consumer is a bit vague. Consumer requires a command bus. The problem is that when an event middleware is passed to the command bus and one of the listeners is used, the listener requires the consumer. This circular-like dependency is bad.
The proposed solution:
This way the tree becomes linear as the command bus can be the last initiated class: