@@ -79,12 +79,14 @@ when compiling the container. Read the sidebar below for more details.
79
79
Using a Service from a narrower Scope
80
80
-------------------------------------
81
81
82
- If your service has a dependency on a scoped service (like the ``request ``),
83
- you have three ways to deal with it:
82
+ The most common problem with "scope" is when your service has a dependency
83
+ on the ``request `` service. The *easiest * way to solve this is to instead
84
+ inject the ``request_stack `` service and access the current Request by calling
85
+ the ``getCurrentRequest() `` method.
84
86
85
- * Use setter injection if the dependency is "synchronized"; this is the
86
- recommended way and the best solution for the `` request `` instance as it is
87
- synchronized with the `` request `` scope (see
87
+ This solution is great, but there are also others:
88
+
89
+ * Use setter injection if the dependency is "synchronized"; (see
88
90
:ref: `using-synchronized-service `).
89
91
90
92
* Put your service in the same scope as the dependency (or a narrower one). If
@@ -108,7 +110,7 @@ Using a synchronized Service
108
110
109
111
Injecting the container or setting your service to a narrower scope have
110
112
drawbacks. For synchronized services (like the ``request ``), using setter
111
- injection is the best option as it has no drawbacks and everything works
113
+ injection is a nice option as it has no drawbacks and everything works
112
114
without any special code in your service or in your definition::
113
115
114
116
// src/Acme/HelloBundle/Mail/Mailer.php
0 commit comments