@@ -36,6 +36,8 @@ until you interact with the proxy in some way.
3636 Starting from Symfony 6.2, service laziness is supported out of the box
3737 without having to install any additional package.
3838
39+ .. _lazy-services_configuration :
40+
3941Configuration
4042-------------
4143
@@ -88,6 +90,26 @@ To check if your lazy service works you can check the interface of the received
8890 dump(class_implements($service));
8991 // the output should include "Symfony\Component\VarExporter\LazyGhostObjectInterface"
9092
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+
91113Interface Proxifying
92114--------------------
93115
@@ -146,6 +168,27 @@ specific interfaces.
146168 ;
147169 };
148170
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+
149192The virtual `proxy `_ injected into other services will only implement the
150193specified interfaces and will not extend the original service class, allowing to
151194lazy load services using `final `_ classes. You can configure the proxy to
0 commit comments