-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Closed
Closed
Copy link
Labels
DependencyInjectionHelp wantedIssues and PRs which are looking for volunteers to complete them.Issues and PRs which are looking for volunteers to complete them.
Description
Description
If I create an http client:
http_client:
scoped_clients:
githubApi:
scope: 'https://api\.github\.com'
headers:
Accept: 'application/vnd.github.v3+json'
And I want to inject it into my service, I can do:
public function __construct(
#[Target('githubApi2')]
private HttpClientInterface $something,
) {
}
But oups, I made a typo. I wrote githubApi2
instead of githubApi
. But for Symfony it's OK. Instead it injects a new "blank" HttpClient (with no sane default configuration - no timeout for example).
IMHO, if one want to inject a specific target, the target must be validated. And if the target does not exist, because another developer renamed it, you want an exception. for this.
see this comments for a previous discussion.
But IMHO, if the naming is not exactly the same as the autowire alias, it's fine to not raise an exception. But in this very use case, you really want this alias. Not another one.
So I would expect an exception.
WDYT?
Example
No response
Korbeil, bastnic, alexandre-daubois, ro0NL, ternel and 1 more
Metadata
Metadata
Assignees
Labels
DependencyInjectionHelp wantedIssues and PRs which are looking for volunteers to complete them.Issues and PRs which are looking for volunteers to complete them.