Skip to content

Commit 6f05767

Browse files
Tirieljaviereguiluz
authored andcommitted
[DependencyInjection] Add #[Lazy] attribute
1 parent 05978f1 commit 6f05767

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

reference/attributes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Dependency Injection
3737
* :ref:`AutowireLocator <service-locator_autowire-locator>`
3838
* :ref:`AutowireServiceClosure <autowiring_closures>`
3939
* :ref:`Exclude <service-psr4-loader>`
40+
* :ref:`Lazy <lazy-services_configuration>`
4041
* :ref:`TaggedIterator <tags_reference-tagged-services>`
4142
* :ref:`TaggedLocator <service-subscribers-locators_defining-service-locator>`
4243
* :ref:`Target <autowiring-multiple-implementations-same-type>`

service_container/lazy_services.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,32 @@ laziness, and supports lazy-autowiring of intersection types::
124124
) {
125125
}
126126

127+
Another possibility is to use the :class:`Symfony\\Component\\DependencyInjection\\Attribute\\Lazy` attribute::
128+
129+
namespace App\Twig;
130+
131+
use Symfony\Component\DependencyInjection\Attribute\Lazy;
132+
use Twig\Extension\ExtensionInterface;
133+
134+
#[Lazy]
135+
class AppExtension implements ExtensionInterface
136+
{
137+
// ...
138+
}
139+
140+
This attribute can be used on a class or on a parameter which should be lazy-loaded, and has a parameter
141+
that also supports defining interfaces to proxy and intersection types::
142+
143+
public function __construct(
144+
#[Lazy(FooInterface::class)]
145+
FooInterface|BarInterface $foo,
146+
) {
147+
}
148+
149+
.. versionadded:: 7.1
150+
151+
The ``#[Lazy]`` attribute was introduced in Symfony 7.1.
152+
127153
Interface Proxifying
128154
--------------------
129155

0 commit comments

Comments
 (0)