P
P
P7472020-02-29 17:07:49
symfony
P747, 2020-02-29 17:07:49

Symfony - how to put your service implementation in a container?

Good afternoon, please tell me, preferably with examples. How to place your service implementation in the container, where to do it? In my case "controller_resolver".

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Flying, 2020-02-29
@P747

There are several ways here:

  1. If it's something simple and you're working with the Symfony Framework (i.e. not with a standalone container) - then you just need to describe your service in the services configuration (in Symfony 4 and above it is config/services.yaml). How this is done is described in the documentation . A description of the standard controller_resolvercan be seen here , in Yaml it will look like this:
    services:
      controller_resolver:
        class: Full\Name\Of\Your\Implementation
        arguments:
         - '@service_container'
         - '@?logger'
       tags: 
         - {'name:':'monolog.logger', channel: 'request'}

    your implementation may of course differ in dependencies.
  2. If this is something more complicated, then the services are configured through the compiler pass . In them you have full access to ContainerBuilderand can programmatically form everything you need in it. However, it is doubtful that in this case you will need it.

In general, all these issues are discussed in great detail in the documentation of the Dependency Injection component .

K
kafkiansky, 2020-02-29
@mad_maximus

https://symfony.com/doc/current/service_container....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question