Symfony 2.5: Decorated services, i.e. replace a service, keep a reference

By am 16.11.2014 in Blog, Symfony | 0 comments

When I found out on Github that Symfony 2.5 added a new dynamic configuration feature for the Dependency Injection Container I got curious:

Symfony 2.5 offers the new feature of keeping a reference to the previous (replaced) service when you dynamically put another one in its place. This is called decorating a service and is described in the documentation

Please think twice before doing this. If there’s another way to achieve what you want without replacing existing services (and thus reducing the risk of confusion on behalf of other developers) choose the most simple way! However: I like the idea of keeping a reference the the original service (and even being able to inject the original by it’s alias if needed) if you really really want to do it.

My personal no. 1 new feature in Symfony 2.5 is still the new option to dump the full current configuration from the console.

Kommentar absenden