@@ -36,6 +36,8 @@ until you interact with the proxy in some way.
36
36
Starting from Symfony 6.2, service laziness is supported out of the box
37
37
without having to install any additional package.
38
38
39
+ .. _lazy-services_configuration :
40
+
39
41
Configuration
40
42
-------------
41
43
@@ -88,6 +90,26 @@ To check if your lazy service works you can check the interface of the received
88
90
dump(class_implements($service));
89
91
// the output should include "Symfony\Component\VarExporter\LazyGhostObjectInterface"
90
92
93
+ You can also configure your service's laziness thanks to the
94
+ :class: `Symfony\\ Component\\ DependencyInjection\\ Attribute\\ Autoconfigure ` attribute.
95
+ For example, to define your service as lazy use the following::
96
+
97
+ namespace App\Twig;
98
+
99
+ use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
100
+ use Twig\Extension\ExtensionInterface;
101
+
102
+ #[Autoconfigure(lazy: true)]
103
+ class AppExtension implements ExtensionInterface
104
+ {
105
+ // ...
106
+ }
107
+
108
+ .. versionadded :: 5.4
109
+
110
+ The :class: `Symfony\\ Component\\ DependencyInjection\\ Attribute\\ Autoconfigure ` attribute
111
+ was introduced in Symfony 5.4.
112
+
91
113
Interface Proxifying
92
114
--------------------
93
115
@@ -146,6 +168,27 @@ specific interfaces.
146
168
;
147
169
};
148
170
171
+ Just like in the :ref: `Configuration <lazy-services_configuration >` section, you can
172
+ use the :class: `Symfony\\ Component\\ DependencyInjection\\ Attribute\\ Autoconfigure `
173
+ attribute to configure the interface to proxify by passing its FQCN as the ``lazy ``
174
+ parameter value::
175
+
176
+ namespace App\Twig;
177
+
178
+ use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
179
+ use Twig\Extension\ExtensionInterface;
180
+
181
+ #[Autoconfigure(lazy: ExtensionInterface::class)]
182
+ class AppExtension implements ExtensionInterface
183
+ {
184
+ // ...
185
+ }
186
+
187
+ .. versionadded :: 5.4
188
+
189
+ The :class: `Symfony\\ Component\\ DependencyInjection\\ Attribute\\ Autoconfigure ` attribute
190
+ was introduced in Symfony 5.4.
191
+
149
192
The virtual `proxy `_ injected into other services will only implement the
150
193
specified interfaces and will not extend the original service class, allowing to
151
194
lazy load services using `final `_ classes. You can configure the proxy to
0 commit comments