Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit89ae736

Browse files
[DI] Tell about #[AutowireInline]
1 parentd90c725 commit89ae736

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

‎service_container/autowiring.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,38 @@ typed properties:
862862
}
863863
}
864864
865+
Autowiring Anonymous Services Inline
866+
------------------------------------
867+
868+
..versionadded::7.2
869+
870+
The ``#[AutowireInline]`` attribute was added in Symfony 7.2.
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+
865897
Autowiring Controller Action Methods
866898
------------------------------------
867899

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp