0

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>
1
  • You can list the id and the corresponding classes of all of the available services using app/console container:debug. Handy if you don't know the names. Commented Jan 22, 2015 at 12:27

1 Answer 1

1

The id for the argument should be 'service_container'

Do

<service id="command_dispatcher" class="CommandDispatcher">
    <argument type="service" id="service_container"/>
</service>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.