Dynamically configure symfony service ID using parameters


If you like in his Depnedency configuration of injection (services.yml) the service injections make dynamically configurable wants about the parameters.yml,

parameters:
    my_class: 'App\MyClass'

can you do this using the Symfony expression language component do:

composer require symfony/expression-language

Then you can define in the services.yml:

services:
    App\Command\MyCommand:
      arguments:
        - '@=service(parameter("my_class"))'

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>