@@ -12,10 +12,11 @@ This entry is all about scopes, a somewhat advanced topic related to the
12
12
13
13
If you are trying to inject the ``request `` service, the simple solution
14
14
is to inject the ``request_stack `` service instead and access the current
15
- Request by calling the ``getCurrentRequest() `` method (see :ref: `book-container-request-stack `).
16
- The rest of this entry talks about scopes in a theoretical and more advanced
17
- way. If you're dealing with scopes for the ``request `` service, simply
18
- inject ``request_stack ``.
15
+ Request by calling the
16
+ :method: `Symfony\\ Component\\ HttpFoundation\\ RequestStack::getCurrentRequest `
17
+ method (see :ref: `book-container-request-stack `). The rest of this entry
18
+ talks about scopes in a theoretical and more advanced way. If you're
19
+ dealing with scopes for the ``request `` service, simply inject ``request_stack ``.
19
20
20
21
Understanding Scopes
21
22
--------------------
@@ -35,7 +36,7 @@ also defines a third scope: ``request``. This scope is tied to the request,
35
36
meaning a new instance is created for each subrequest and is unavailable
36
37
outside the request (for instance in the CLI).
37
38
38
- An Example: client Scope
39
+ An Example: Client Scope
39
40
~~~~~~~~~~~~~~~~~~~~~~~~
40
41
41
42
Other than the ``request `` service (which has a simple solution, see the
@@ -92,13 +93,13 @@ when compiling the container. Read the sidebar below for more details.
92
93
A service can of course depend on a service from a wider scope without
93
94
any issue.
94
95
95
- Using a Service from a narrower Scope
96
+ Using a Service from a Narrower Scope
96
97
-------------------------------------
97
98
98
99
There are several solutions to the scope problem:
99
100
100
- * A) Use setter injection if the dependency is " synchronized"; (see
101
- :ref: `using-synchronized-service `).
101
+ * A) Use setter injection if the dependency is `` synchronized `` (see
102
+ :ref: `using-synchronized-service `);
102
103
103
104
* B) Put your service in the same scope as the dependency (or a narrower one). If
104
105
you depend on the ``client_configuration `` service, this means putting your
@@ -107,13 +108,13 @@ There are several solutions to the scope problem:
107
108
* C) Pass the entire container to your service and retrieve your dependency from
108
109
the container each time you need it to be sure you have the right instance
109
110
-- your service can live in the default ``container `` scope (see
110
- :ref: `passing-container `);
111
+ :ref: `passing-container `).
111
112
112
113
Each scenario is detailed in the following sections.
113
114
114
115
.. _using-synchronized-service :
115
116
116
- A) Using a synchronized Service
117
+ A) Using a Synchronized Service
117
118
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
118
119
119
120
.. versionadded :: 2.3
0 commit comments