0
votes

I'm starting a new project using Symfony 3.3. I'm would like to use the new autoconfigure/autowiring features but I'm running into an "issue" I'm not sure how to solve.

I have the following services definition coming from an external bundle:

command_bus:
    class: Name\Space\To\MessageBusSupportingMiddleware
    ...

event_bus:
    class: Name\Space\To\MessageBusSupportingMiddleware
    ...

Both services are based on the same "MessageBusSupportingMiddleware" class but their intention is totally different of course.

Now I want Symfony 3.3 to automatically inject the "command_bus" service into my controller. But for this, I would have to use the class in the constructor like this:

public function __construct(
    MessageBusSupportingMiddleware $commandBus
){
    $this->commandBus = $commandBus;
}

In this case though, Symfony complains because it actually finds several service definition related to this class and so it cannot know which one to provide.

How do you think I could handle this situation ?

1

1 Answers

0
votes

I actually find a way to overcome this situation.

I have create two classes in my own project:

class CommandBus  extends MessageBusSupportingMiddleware
{
}

class EventBus  extends MessageBusSupportingMiddleware
{
}

Their only purpose is to be able to override the default service definition from the external bundle and use different implementation to be able to autowire them. My service override configuration is simply done in a services.yml file as such:

services:

    command_bus:
        class: CoreBundle\Bus\CommandBus

    event_bus:
        class: CoreBundle\Bus\EventBus