Skip to content

Commit d8804cb

Browse files
committed
minor #18106 [DependencyInjection] Add support for #[Autowire(lazy: true)] (MrYamous)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [DependencyInjection] Add support for `#[Autowire(lazy: true)]` Fixes #18095 I'm wondering if this argument should be documented [here](https://symfony.com/doc/current/service_container/autowiring.html#autowire-attribute) (where the attribute in mainly mentioned) or if it is fine to split considering the page about service lazy loading is relevant for this arg ? Commits ------- 527c24a [DependencyInjection] Add support for `#[Autowire(lazy: true)]`
2 parents 8e5736c + 527c24a commit d8804cb

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
@@ -103,6 +103,29 @@ For example, to define your service as lazy use the following::
103103
// ...
104104
}
105105

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

0 commit comments

Comments
 (0)