Skip to content

[DependencyInjection] Add a note about configuring controllers without autowire/autoconfigure #19342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions controller/service.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,40 @@ in method parameters:
resource: '../src/Controller/'
tags: ['controller.service_arguments']

.. note::

If you don't use either :doc:`autowiring </service_container/autowiring>`
or :ref:`autoconfiguration <services-autoconfigure>` and you extend the
``AbstractController``, you'll need to apply other tags and make some method
calls to register your controllers as services:

.. code-block:: yaml

# config/services.yaml

# this extended configuration is only required when not using autowiring/autoconfiguration,
# which is uncommon and not recommended

abstract_controller.locator:
class: Symfony\Component\DependencyInjection\ServiceLocator
arguments:
-
router: '@router'
request_stack: '@request_stack'
http_kernel: '@http_kernel'
session: '@session'
parameter_bag: '@parameter_bag'
# you can add more services here as you need them (e.g. the `serializer`
# service) and have a look at the AbstractController class to see
# which services are defined in the locator

App\Controller\:
resource: '../src/Controller/'
tags: ['controller.service_arguments']
calls:
- [setContainer, ['@abstract_controller.locator']]


If you prefer, you can use the ``#[AsController]`` PHP attribute to automatically
apply the ``controller.service_arguments`` tag to your controller services::

Expand Down