File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -862,6 +862,33 @@ typed properties:
862
862
}
863
863
}
864
864
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 $githubClient,
884
+ )
885
+
886
+ As you might have already figured out, this declaration instructs Symfony to inject an
887
+ object created by calling the ``ScopingHttpClient::forBaseUri() `` factory with the
888
+ configured base URI and default options.
889
+
890
+ Of course, this is just an example and this attribute can be used to construct any kind of objects.
891
+
865
892
Autowiring Controller Action Methods
866
893
------------------------------------
867
894
You can’t perform that action at this time.
0 commit comments