Description
Description
When configure your busses it could look like this:
framework:
messenger:
default_bus: messenger.bus.command
buses:
messenger.bus.command:
middleware:
- App\Message\Middleware\SpecialLoggingMiddleware
- validation
- doctrine_transaction
messenger.bus.event:
default_middleware: allow_no_handlers
middleware:
- validation
messenger.bus.query:
middleware:
- validation
Since we are using multiple busses we are forced to define default_bus
. Why?
I understand it is for autowire but what if I dont want it to autowire?
The issue is the following:
I define my services like
services:
_defaults:
autowire: true
autoconfigure: true
bind:
$eventBus: '@messenger.bus.event'
$commandBus: '@messenger.bus.command'
So if I create two PHP classes like this:
class Foo{
private $eventBus;
public function __construct(MessageBusInterface $eventBus) {
$this->eventBus = $eventBus;
}
}
class Bar{
private $queryBus;
public function __construct(MessageBusInterface $queryBus) {
$this->queryBus = $queryBus;
}
}
Foo
will get an instance of my messenger.bus.event
and Bar
will get an instance of messenger.bus.command
. You would expect Bar
to get messenger.bus.query
, but I've forgotten to add that under services._default.bind
and autowire "helps" me to get the configured default_bus
.
I would much rather not define a default_bus
and then get an exception since it cannot autowire MessageBusInterface $queryBus
.
Im sure there is a reason why we need a default_bus
but I cannot see it.