thephpleague / tactician-bernard

Tactician integration with the Bernard queueing library
MIT License
19 stars 3 forks source link

Make dependency tree more simple #6

Closed sagikazarmark closed 9 years ago

sagikazarmark commented 9 years ago

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:

sagikazarmark commented 9 years ago

See #8