Skip to content

Commit 096046c

Browse files
committed
minor #7495 Improved the advantages/drawbacks of "controllers as services" (javiereguiluz)
This PR was merged into the 2.7 branch. Discussion ---------- Improved the advantages/drawbacks of "controllers as services" This fixes #6749. Commits ------- e8b9e62 Improved the advantages/drawbacks of "controllers as services"
2 parents dcde03c + e8b9e62 commit 096046c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

controller/service.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@ These are the main **advantages** of defining controllers as services:
2323
service container configuration. This is useful when developing reusable bundles;
2424
* Your controllers are more "sandboxed". By looking at the constructor arguments,
2525
it's easy to see what types of things this controller may or may not do;
26+
* If you're not passing some required dependencies or if you are injecting some
27+
non-existent services, you'll get errors during the container compilation
28+
instead of during runtime execution;
2629
* Since dependencies must be injected manually, it's more obvious when your
2730
controller is becoming too big (i.e. if you have many constructor arguments).
2831

2932
These are the main **drawbacks** of defining controllers as services:
3033

31-
* It takes more work to create the controllers because they don't have
32-
automatic access to the services or to the base controller shortcuts;
34+
* It takes more work to create the controllers and they become more verbose
35+
because they don't have automatic access to the services and the base
36+
controller shortcuts;
3337
* The constructor of the controllers can rapidly become too complex because you
34-
must inject every single dependency needed by them;
35-
* The code of the controllers is more verbose because you can't use the shortcuts
36-
of the base controller and you must replace them with some lines of code.
38+
must inject every single dependency needed by them.
3739

3840
The recommendation from the :doc:`best practices </best_practices/controllers>`
3941
is also valid for controllers defined as services: avoid putting your business

0 commit comments

Comments
 (0)