Skip to content

Commit d1052b2

Browse files
committed
minor #19506 [DependencyInjection] Add #[Lazy] attribute (Tiriel)
This PR was squashed before being merged into the 7.1 branch. Discussion ---------- [DependencyInjection] Add `#[Lazy]` attribute Fixes #19486 Documentation for the new `#[Lazy]` attribute. Commits ------- 6f05767 [DependencyInjection] Add `#[Lazy]` attribute
2 parents 4f7b018 + 6f05767 commit d1052b2

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 union 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)