44How to Decorate Services
55======================== 
66
7- When overriding an existing definition (e.g. when applying the `Decorator pattern `_),
8- the original service is lost:
7+ When overriding an existing definition, the original service is lost:
98
109.. configuration-block ::
1110
@@ -18,7 +17,7 @@ the original service is lost:
1817 #  this replaces the old AppBundle\Mailer definition with the new one, the 
1918 #  old definition is lost 
2019 AppBundle\Mailer : 
21-  class : AppBundle\DecoratingMailer   
20+  class : AppBundle\NewMailer   
2221
2322code-block :: xml 
2423
@@ -33,25 +32,27 @@ the original service is lost:
3332
3433 <!--  this replaces the old AppBundle\Mailer definition with the new 
3534 one, the old definition is lost -->  
36-  <service  id =" AppBundle\Mailer" class =" AppBundle\DecoratingMailer "  
35+  <service  id =" AppBundle\Mailer" class =" AppBundle\NewMailer "  
3736 </services > 
3837 </container > 
3938
4039code-block :: php 
4140
4241 // config/services.php 
4342 use AppBundle\Mailer; 
44-  use AppBundle\DecoratingMailer ; 
43+  use AppBundle\NewMailer ; 
4544
4645 $container->register(Mailer::class); 
4746
4847 // this replaces the old AppBundle\Mailer definition with the new one, the 
4948 // old definition is lost 
50-  $container->register(Mailer::class, DecoratingMailer ::class); 
49+  $container->register(Mailer::class, NewMailer ::class); 
5150
5251
53- you might want to decorate the old service instead and keep the old service so
54- that you can reference it:
52+ you might want to decorate the old one instead (i.e. apply the `Decorator pattern `_).
53+ In this case, the old service should be kept around to be able to reference
54+ it in the new one. This configuration replaces ``app.mailer `` with a new one,
55+ but keeps a reference of the old one as ``app.decorating_mailer.inner ``:
5556
5657.. configuration-block ::
5758
0 commit comments