Skip to content

Commit 872c8ad

Browse files
committed
Add Lazy attribute documentation
1 parent 05978f1 commit 872c8ad

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
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: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,18 @@ To check if your lazy service works you can check the interface of the received
8484
// the output should include "Symfony\Component\VarExporter\LazyObjectInterface"
8585

8686
You can also configure your service's laziness thanks to the
87-
:class:`Symfony\\Component\\DependencyInjection\\Attribute\\Autoconfigure` attribute.
87+
:class:`Symfony\\Component\\DependencyInjection\\Attribute\\Autoconfigure` or the
88+
:class:`Symfony\\Component\\DependencyInjection\\Attribute\\Lazy` attribute.
8889
For example, to define your service as lazy use the following::
8990

9091
namespace App\Twig;
9192

9293
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
94+
// use Symfony\Component\DependencyInjection\Attribute\Lazy;
9395
use Twig\Extension\ExtensionInterface;
9496

9597
#[Autoconfigure(lazy: true)]
98+
// #[Lazy]
9699
class AppExtension implements ExtensionInterface
97100
{
98101
// ...
@@ -124,6 +127,16 @@ laziness, and supports lazy-autowiring of intersection types::
124127
) {
125128
}
126129

130+
If you don't need to specify a service ID, the
131+
:class:`Symfony\\Component\\DependencyInjection\\Attribute\\Lazy` attribute
132+
can also be used as a shortcut::
133+
134+
public function __construct(
135+
#[Lazy(lazy: FooInterface::class)]
136+
FooInterface|BarInterface $foo,
137+
) {
138+
}
139+
127140
Interface Proxifying
128141
--------------------
129142

0 commit comments

Comments
 (0)