@@ -208,6 +208,8 @@ instance of ``Symfony\Component\HttpKernel\Event\FilterResponseEvent``::
208
208
.. sidebar :: Registering Event Listeners in the Service Container
209
209
210
210
When you are using the
211
+ :class: `Symfony\\ Component\\ EventDispatcher\\ ContainerAwareEventDispatcher `
212
+ and the
211
213
:doc: `DependencyInjection component </components/dependency_injection/introduction >`,
212
214
you can use the
213
215
:class: `Symfony\\ Component\\ HttpKernel\\ DependencyInjection\\ RegisterListenersPass `
@@ -216,16 +218,17 @@ instance of ``Symfony\Component\HttpKernel\Event\FilterResponseEvent``::
216
218
use Symfony\Component\DependencyInjection\ContainerBuilder;
217
219
use Symfony\Component\DependencyInjection\Definition;
218
220
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
221
+ use Symfony\Component\DependencyInjection\Reference;
219
222
use Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPass;
220
223
221
224
$containerBuilder = new ContainerBuilder(new ParameterBag());
222
225
$containerBuilder->addCompilerPass(new RegisterListenersPass());
223
226
224
227
// 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
+ )) ;
229
232
230
233
// register your event listener service
231
234
$listener = new Definition('AcmeListener');
0 commit comments