File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -862,6 +862,38 @@ 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 one can define anonymous services inline using configuration files,
873+ the :class: `Symfony\\ Component\\ DependencyInjection\\ Attribute\\ AutowireInline `
874+ attribute allows declaring anonymous services inline next to their corresponding
875+ 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+ As you might have already figured out, this declaration instructs Symfony to inject an
892+ object created by calling the ``ScopingHttpClient::forBaseUri() `` factory with the
893+ configured base URI and default options.
894+
895+ Of course, this is just an example and this attribute can be used to construct any kind of objects.
896+
865897Autowiring Controller Action Methods
866898------------------------------------
867899
You can’t perform that action at this time.
0 commit comments