Steven Teerlinck
Steven Teerlinck

Reputation: 3

Symfony2 Service with container as a dependancy

In Symfony2, is it possible to define a Service in the Service Container that has the Service Container as a dependance? I'm trying to build a CommandDispatcher which will pass a Command to the appropriate CommandHandler. To be able to do this, the CommandDispatcher needs the Container to query it for the appropriate CommandHandler.

Example service XML:

<service id="command_dispatcher" class="CommandDispatcher">
    <argument type="service" id="Container"/>
</service>

Upvotes: 0

Views: 38

Answers (1)

Nico Kaag
Nico Kaag

Reputation: 1886

The id for the argument should be 'service_container'

Do

<service id="command_dispatcher" class="CommandDispatcher">
    <argument type="service" id="service_container"/>
</service>

Upvotes: 1

Related Questions