@@ -208,6 +208,8 @@ instance of ``Symfony\Component\HttpKernel\Event\FilterResponseEvent``::
208208.. sidebar :: Registering Event Listeners in the Service Container
209209
210210 When you are using the
211+ :class: `Symfony\\ Component\\ EventDispatcher\\ ContainerAwareEventDispatcher `
212+ and the
211213 :doc: `DependencyInjection component </components/dependency_injection/introduction >`,
212214 you can use the
213215 :class: `Symfony\\ Component\\ HttpKernel\\ DependencyInjection\\ RegisterListenersPass `
@@ -216,16 +218,17 @@ instance of ``Symfony\Component\HttpKernel\Event\FilterResponseEvent``::
216218 use Symfony\Component\DependencyInjection\ContainerBuilder;
217219 use Symfony\Component\DependencyInjection\Definition;
218220 use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
221+ use Symfony\Component\DependencyInjection\Reference;
219222 use Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPass;
220223
221224 $containerBuilder = new ContainerBuilder(new ParameterBag());
222225 $containerBuilder->addCompilerPass(new RegisterListenersPass());
223226
224227 // register the event dispatcher service
225- $containerBuilder->register (
226- 'event_dispatcher ',
227- 'Symfony\Component\EventDispatcher\EventDispatcher'
228- );
228+ $containerBuilder->setDefinition('event_dispatcher', new Definition (
229+ 'Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher ',
230+ array(new Reference('service_container'))
231+ )) ;
229232
230233 // register your event listener service
231234 $listener = new Definition('AcmeListener');
0 commit comments