Create Service implementing ContainerAwareInterface

symfony

Solution

Make a definition in your services.yml file

services:
    bundle.service_name: 
        class: ...
        calls:
            - [ setContainer, [ @service_container ] ]

Problem

The service don't invoke setContainer when I extend ContainerAware or implement ContainerAwareInterface. ``` class CustomService implements ContainerAwareInterface { public function setContainer(ContainerInterface $container = null) { $this->container = $container; } } ``` How can I use the container from my service without injection one? Is it required to pass the container object to the constructor or a setter?

Original source