Skip to content

Commit 2225fe4

Browse files
committed
Create new paragraph for and add versionadded directive
1 parent 872c8ad commit 2225fe4

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

service_container/lazy_services.rst

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,12 @@ 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` or the
88-
:class:`Symfony\\Component\\DependencyInjection\\Attribute\\Lazy` attribute.
87+
:class:`Symfony\\Component\\DependencyInjection\\Attribute\\Autoconfigure` attribute.
8988
For example, to define your service as lazy use the following::
9089

9190
namespace App\Twig;
9291

9392
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
94-
// use Symfony\Component\DependencyInjection\Attribute\Lazy;
9593
use Twig\Extension\ExtensionInterface;
9694

9795
#[Autoconfigure(lazy: true)]
@@ -127,16 +125,32 @@ laziness, and supports lazy-autowiring of intersection types::
127125
) {
128126
}
129127

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::
128+
Another possibility is to use the :class:`Symfony\\Component\\DependencyInjection\\Attribute\\Lazy` attribute::
129+
130+
namespace App\Twig;
131+
132+
use Symfony\Component\DependencyInjection\Attribute\Lazy;
133+
use Twig\Extension\ExtensionInterface;
134+
135+
#[Lazy]
136+
class AppExtension implements ExtensionInterface
137+
{
138+
// ...
139+
}
140+
141+
This attribute can be used on a class or on an argument which should be lazy-loaded, and has a `lazy` parameter
142+
that also supports defining interfaces to proxy and intersection types::
133143

134144
public function __construct(
135145
#[Lazy(lazy: FooInterface::class)]
136146
FooInterface|BarInterface $foo,
137147
) {
138148
}
139149

150+
.. versionadded:: 7.1
151+
152+
The ``#[Lazy]`` attribute was introduced in Symfony 7.1.
153+
140154
Interface Proxifying
141155
--------------------
142156

0 commit comments

Comments
 (0)