8000 [#2956] A few more changes to the scopes chapter to update the new wa… · symfony/symfony-docs@b84f52c · GitHub
[go: up one dir, main page]

Skip to content

Commit b84f52c

Browse files
committed
[#2956] A few more changes to the scopes chapter to update the new way of working with the request service
1 parent 3548a51 commit b84f52c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

cookbook/service_container/scopes.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ when compiling the container. Read the sidebar below for more details.
7979
Using a Service from a narrower Scope
8080
-------------------------------------
8181

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.
8486

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
8890
:ref:`using-synchronized-service`).
8991

9092
* Put your service in the same scope as the dependency (or a narrower one). If
@@ -108,7 +110,7 @@ Using a synchronized Service
108110

109111
Injecting the container or setting your service to a narrower scope have
110112
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
112114
without any special code in your service or in your definition::
113115

114116
// src/Acme/HelloBundle/Mail/Mailer.php

0 commit comments

Comments
 (0)
0