@@ -41,6 +41,8 @@ In order to use the lazy service instantiation, you will need to install the
41
41
42
42
$ composer require symfony/proxy-manager-bridge
43
43
44
+ .. _lazy-services_configuration :
45
+
44
46
Configuration
45
47
-------------
46
48
@@ -101,6 +103,26 @@ To check if your proxy works you can check the interface of the received object:
101
103
over the ``lazy `` flag and directly instantiate the service as it would
102
104
normally do.
103
105
106
+ You can also configure your service's laziness thanks to the
107
+ :class: `Symfony\\ Component\\ DependencyInjection\\ Attribute\\ Autoconfigure ` attribute.
108
+ The attribute has to be used like this::
109
+
110
+ namespace App\Twig;
111
+
112
+ use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
113
+ use Twig\Extension\ExtensionInterface;
114
+
115
+ #[Autoconfigure(lazy: true)]
116
+ class AppExtension implements ExtensionInterface
117
+ {
118
+ // ...
119
+ }
120
+
121
+ .. versionadded :: 5.4
122
+
123
+ The :class: `Symfony\\ Component\\ DependencyInjection\\ Attribute\\ Autoconfigure ` attribute
124
+ was introduced in Symfony 5.4.
125
+
104
126
Interface Proxifying
105
127
--------------------
106
128
@@ -159,6 +181,27 @@ specific interfaces.
159
181
;
160
182
};
161
183
184
+ Just like in the :ref: `Configuration <lazy-services_configuration >` section, you can
185
+ use the :class: `Symfony\\ Component\\ DependencyInjection\\ Attribute\\ Autoconfigure `
186
+ attribute to configure the interface to proxify by passing its FQCN as the ``lazy ``
187
+ parameter value::
188
+
189
+ namespace App\Twig;
190
+
191
+ use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
192
+ use Twig\Extension\ExtensionInterface;
193
+
194
+ #[Autoconfigure(lazy: ExtensionInterface::class)]
195
+ class AppExtension implements ExtensionInterface
196
+ {
197
+ // ...
198
+ }
199
+
200
+ .. versionadded :: 5.4
201
+
202
+ The :class: `Symfony\\ Component\\ DependencyInjection\\ Attribute\\ Autoconfigure ` attribute
203
+ was introduced in Symfony 5.4.
204
+
162
205
The virtual `proxy `_ injected into other services will only implement the
163
206
specified interfaces and will not extend the original service class, allowing to
164
207
lazy load services using `final `_ classes. You can configure the proxy to
0 commit comments