Skip to content

Commit b408ab8

Browse files
[LazyServices] Add #[Autoconfigure] attribute mention
1 parent cb6da54 commit b408ab8

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

service_container/lazy_services.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ In order to use the lazy service instantiation, you will need to install the
4141
4242
$ composer require symfony/proxy-manager-bridge
4343
44+
.. _lazy-services_configuration:
45+
4446
Configuration
4547
-------------
4648

@@ -101,6 +103,26 @@ To check if your proxy works you can check the interface of the received object:
101103
over the ``lazy`` flag and directly instantiate the service as it would
102104
normally do.
103105

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+
104126
Interface Proxifying
105127
--------------------
106128

@@ -159,6 +181,27 @@ specific interfaces.
159181
;
160182
};
161183
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+
162205
The virtual `proxy`_ injected into other services will only implement the
163206
specified interfaces and will not extend the original service class, allowing to
164207
lazy load services using `final`_ classes. You can configure the proxy to

0 commit comments

Comments
 (0)