File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change 44How to Define Controllers as Services
55=====================================
66
7- In Symfony, a controller does *not * need to be registered as a service. But if you're
8- using the :ref: `default services.yaml configuration <service-container-services-load-example >`,
9- and that your controllers extend the `AbstractController `_ class,
10- they *are * already registered as services. This means you can use dependency
11- injection like any other normal service.
12-
13- If your controllers don't extend the `AbstractController `_ class, you must explicitly mark your controller
14- services as ``public ``.
15- Alternatively, you can also tag controller services with the ``controller.service_arguments ``.
16- This will make the tagged services ``public `` and will allow you to inject services in method parameters:
7+ In Symfony, a controller does *not * need to be registered as a service. But if
8+ you're using the :ref: `default services.yaml configuration <service-container-services-load-example >`,
9+ and your controllers extend the `AbstractController `_ class, they *are * automatically
10+ registered as services. This means you can use dependency injection like any
11+ other normal service.
12+
13+ If your controllers don't extend the `AbstractController `_ class, you must
14+ explicitly mark your controller services as ``public ``. Alternatively, you can
15+ apply the ``controller.service_arguments `` tag to your controller services. This
16+ will make the tagged services ``public `` and will allow you to inject services
17+ in method parameters:
1718
1819.. configuration-block ::
1920
You can’t perform that action at this time.
0 commit comments