File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -862,6 +862,34 @@ typed properties:
862862 }
863863 }
864864
865+ Autowiring Anonymous Services Inline
866+ ------------------------------------
867+
868+ Similar to how one can define anonymous services inline using configuration files,
869+ the :class: `Symfony\\ Component\\ DependencyInjection\\ Attribute\\ AutowireInline `
870+ attribute allows declaring anonymous services inline next to their corresponding
871+ arguments::
872+
873+ public function __construct(
874+ #[AutowireInline(
875+ factory: [ScopingHttpClient::class, 'forBaseUri'],
876+ arguments: [
877+ '$baseUri' => 'https://api.example.com',
878+ '$defaultOptions' => [
879+ 'auth_bearer' => '%env(EXAMPLE_TOKEN)%',
880+ ],
881+ ]
882+ )]
883+ private HttpClientInterface $client,
884+ ) {
885+ }
886+
887+ As you might have already figured out, this declaration instructs Symfony to inject an
888+ object created by calling the ``ScopingHttpClient::forBaseUri() `` factory with the
889+ configured base URI and default options.
890+
891+ Of course, this is just an example and this attribute can be used to construct any kind of objects.
892+
865893Autowiring Controller Action Methods
866894------------------------------------
867895
You can’t perform that action at this time.
0 commit comments