Skip to content

Commit b9b0cfe

Browse files
committed
minor #19342 [DependencyInjection] Add a note about configuring controllers without autowire/autoconfigure (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- [DependencyInjection] Add a note about configuring controllers without autowire/autoconfigure Fix #16579 Here is my try `@javiereguiluz`, from what I understood in the first PR. This is the minimal configuration I have in my computer to make the AbstractController extend work. I mostly used your wording, changing the required config by defining a locator that could be used for any controller extending AbstractController. Commits ------- 412a450 Add a note about configuring controllers without autowire/autoconfigure
2 parents e9f0d4d + 412a450 commit b9b0cfe

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

controller/service.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,40 @@ in method parameters:
2525
resource: '../src/Controller/'
2626
tags: ['controller.service_arguments']
2727
28+
.. note::
29+
30+
If you don't use either :doc:`autowiring </service_container/autowiring>`
31+
or :ref:`autoconfiguration <services-autoconfigure>` and you extend the
32+
``AbstractController``, you'll need to apply other tags and make some method
33+
calls to register your controllers as services:
34+
35+
.. code-block:: yaml
36+
37+
# config/services.yaml
38+
39+
# this extended configuration is only required when not using autowiring/autoconfiguration,
40+
# which is uncommon and not recommended
41+
42+
abstract_controller.locator:
43+
class: Symfony\Component\DependencyInjection\ServiceLocator
44+
arguments:
45+
-
46+
router: '@router'
47+
request_stack: '@request_stack'
48+
http_kernel: '@http_kernel'
49+
session: '@session'
50+
parameter_bag: '@parameter_bag'
51+
# you can add more services here as you need them (e.g. the `serializer`
52+
# service) and have a look at the AbstractController class to see
53+
# which services are defined in the locator
54+
55+
App\Controller\:
56+
resource: '../src/Controller/'
57+
tags: ['controller.service_arguments']
58+
calls:
59+
- [setContainer, ['@abstract_controller.locator']]
60+
61+
2862
If you prefer, you can use the ``#[AsController]`` PHP attribute to automatically
2963
apply the ``controller.service_arguments`` tag to your controller services::
3064

0 commit comments

Comments
 (0)