Skip to content

Commit 1a79edd

Browse files
committed
[symfony#2538][symfony#2433] Adding a note to the service container chapter about how a controller can be defined as a service
1 parent 278842f commit 1a79edd

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

book/service_container.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ the behavior you'll need (it's more flexible and powerful), but you'll learn
172172
later how you can configure a service that has multiple instances in the
173173
":doc:`/cookbook/service_container/scopes`" cookbook article.
174174

175+
.. note::
176+
177+
In this example, the controller extends Symfony's base Controller, which
178+
gives you access to the service container itself. You can then use the
179+
``get`` method to locate and retrieve the ``my_mailer`` service from
180+
the service container. You can also define your :doc:`controllers as services</cookbook/controller/service>`.
181+
This is a bit more advanced and not necessary, but it allows you to inject
182+
only the services you need into your controller.
183+
175184
.. _book-service-container-parameters:
176185

177186
Service Parameters

0 commit comments

Comments
 (0)