Skip to content

Commit 42f80e0

Browse files
committed
[symfony#2538] Enhancing advantages of a controller as a service
1 parent 1fbd278 commit 42f80e0

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

cookbook/controller/service.rst

+12-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,18 @@ this works fine, controllers can also be specified as services.
1515
primary advantage is that the entire controller or any services passed to
1616
the controller can be modified via the service container configuration.
1717
This is especially useful when developing an open-source bundle or any
18-
bundle that will be used in many different projects. So, even if you don't
19-
specify your controllers as services, you'll likely see this done in some
20-
open-source Symfony2 bundles.
18+
bundle that will be used in many different projects.
19+
20+
A second advantage is that your controllers are more "sandboxed". By
21+
looking at the constructor arguments, it's easy to see what types of things
22+
this controller may or may not do. And because each dependency needs
23+
to be injected manually, it's more obvious (i.e. if you have many constructor
24+
arguments) when your controller has become too big, and may need to be
25+
split into multiple controllers.
26+
27+
So, even if you don't specify your controllers as services, you'll likely
28+
see this done in some open-source Symfony2 bundles. It's also important
29+
to understand the pros and cons of both approaches.
2130

2231
Defining the Controller as a Service
2332
------------------------------------

0 commit comments

Comments
 (0)