@@ -862,6 +862,40 @@ typed properties:
862862 }
863863 }
864864
865+ Autowiring Anonymous Services Inline
866+ ------------------------------------
867+
868+ .. versionadded :: 7.1
869+
870+ The ``#[AutowireInline] `` attribute was added in Symfony 7.1.
871+
872+ Similar to how anonymous services can be defined inline in configuration files,
873+ the :class: `Symfony\\ Component\\ DependencyInjection\\ Attribute\\ AutowireInline `
874+ attribute allows you to declare anonymous services inline, directly next to their
875+ corresponding arguments::
876+
877+ public function __construct(
878+ #[AutowireInline(
879+ factory: [ScopingHttpClient::class, 'forBaseUri'],
880+ arguments: [
881+ '$baseUri' => 'https://api.example.com',
882+ '$defaultOptions' => [
883+ 'auth_bearer' => '%env(EXAMPLE_TOKEN)%',
884+ ],
885+ ]
886+ )]
887+ private HttpClientInterface $client,
888+ ) {
889+ }
890+
891+ This example tells Symfony to inject an object created by calling the
892+ ``ScopingHttpClient::forBaseUri() `` factory with the specified base URI and
893+ default options. This is just one example: you can use the ``#[AutowireInline] ``
894+ attribute to define any kind of anonymous service.
895+
896+ While this approach is convenient for simple service definitions, consider moving
897+ complex or heavily configured services to a configuration file to ease maintenance.
898+
865899Autowiring Controller Action Methods
866900------------------------------------
867901
0 commit comments