Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Clarify the description of the #[Target] attribute or add examples of usage. #19137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Akhristenko opened this issue Nov 15, 2023 · 4 comments
Closed

Comments

@Akhristenko
Copy link

Documentation says: Another possibility is to use the #[Target] attribute. By using this attribute on the argument you want to autowire, you can define exactly which service to inject by using its alias.
According to this documentation and having the following code

interface ProviderInterface {}
class ProviderA implement ProviderInterface {}
class ProviderB implement ProviderInterface {}

i define alias for service in services

correct_provider:
  alias: App\ProviderA

and try to inject it via #[Target] attribute

class JobService {
    public function __construct(#[Target('correct_provider')] ProviderInterface $provider) {}
}

but this don't work.
After viewing the source code, I realized that this should not work.
I think this line in the documentation is misleading.

@javiereguiluz
Copy link
Member

Reading the description of the original code PR (symfony/symfony#40800) I think that the docs tell exactly the same as that original description.

Why do you say that the code can't work as explained in docs? Thanks.

@carsonbot
Copy link
Collaborator

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

@carsonbot
Copy link
Collaborator

Friendly reminder that this issue exists. If I don't hear anything I'll close this.

@carsonbot
Copy link
Collaborator

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants