Skip to content

Commit c4b09ae

Browse files
committed
add support for autowire attribute lazy argument
1 parent 1fcba0b commit c4b09ae

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

service_container/lazy_services.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,29 @@ For example, to define your service as lazy use the following::
106106
// ...
107107
}
108108

109+
You can also configure laziness when your service is injected with
110+
:class:`Symfony\\Component\\DependencyInjection\\Attribute\\Autowire` attribute.
111+
For example, to inject your service as lazy use the following::
112+
113+
namespace App\Service;
114+
115+
use App\Twig\AppExtension;
116+
use Symfony\Component\DependencyInjection\Attribute\Autowire;
117+
118+
class MessageGenerator
119+
{
120+
public function __construct(
121+
#[Autowire(service: 'app.twig.app_extension', lazy: true)] ExtensionInterface $extension
122+
) {
123+
// ...
124+
}
125+
}
126+
127+
.. versionadded:: 6.3
128+
129+
The ``lazy`` argument of the ``#[Autowire()]`` attribute was introduced in
130+
Symfony 6.3.
131+
109132
Interface Proxifying
110133
--------------------
111134

0 commit comments

Comments
 (0)