@@ -84,14 +84,12 @@ To check if your lazy service works you can check the interface of the received
84
84
// the output should include "Symfony\Component\VarExporter\LazyObjectInterface"
85
85
86
86
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.
89
88
For example, to define your service as lazy use the following::
90
89
91
90
namespace App\Twig;
92
91
93
92
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
94
- // use Symfony\Component\DependencyInjection\Attribute\Lazy;
95
93
use Twig\Extension\ExtensionInterface;
96
94
97
95
#[Autoconfigure(lazy: true)]
@@ -127,16 +125,32 @@ laziness, and supports lazy-autowiring of intersection types::
127
125
) {
128
126
}
129
127
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::
133
143
134
144
public function __construct(
135
145
#[Lazy(lazy: FooInterface::class)]
136
146
FooInterface|BarInterface $foo,
137
147
) {
138
148
}
139
149
150
+ .. versionadded :: 7.1
151
+
152
+ The ``#[Lazy] `` attribute was introduced in Symfony 7.1.
153
+
140
154
Interface Proxifying
141
155
--------------------
142
156
0 commit comments