From 527c24a1dc52dbce23438af2c96342566bc1abd7 Mon Sep 17 00:00:00 2001 From: MrYamous Date: Mon, 20 Mar 2023 22:45:19 +0100 Subject: [PATCH] [DependencyInjection] Add support for `#[Autowire(lazy: true)]` --- service_container/lazy_services.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/service_container/lazy_services.rst b/service_container/lazy_services.rst index e69a52bd3dd..736cc44761b 100644 --- a/service_container/lazy_services.rst +++ b/service_container/lazy_services.rst @@ -106,6 +106,29 @@ For example, to define your service as lazy use the following:: // ... } +You can also configure laziness when your service is injected with +:class:`Symfony\\Component\\DependencyInjection\\Attribute\\Autowire` attribute. +For example, to inject your service as lazy use the following:: + + namespace App\Service; + + use App\Twig\AppExtension; + use Symfony\Component\DependencyInjection\Attribute\Autowire; + + class MessageGenerator + { + public function __construct( + #[Autowire(service: 'app.twig.app_extension', lazy: true)] ExtensionInterface $extension + ) { + // ... + } + } + +.. versionadded:: 6.3 + + The ``lazy`` argument of the `#[Autowire()]` attribute was introduced in + Symfony 6.3. + Interface Proxifying --------------------