Skip to content

Navigation Menu

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

Appearance settings

Extend #[AsAlias] to arguments #60158

Copy link
Copy link
Open
@gaizkaeu

Description

@gaizkaeu
Issue body actions

Description

Following #41188 and #47323.

I have multiple implementations for my interface. I want to inject the service typed by its interface + argument. Same as https://symfony.com/doc/current/service_container/autowiring.html#dealing-with-multiple-implementations-of-the-same-type but with attributes.

What do you guys think? I'd be able to create a PR if accepted.

Example

<?php

namespace Foo;

use Symfony\Component\DependencyInjection\Attribute\AsAlias;

#[AsAlias(argument: 'one']
final class MyAdapterClassOne implements \Bar\MyInterface
{
    // ...
}

#[AsAlias(argument: 'two']
final class MyAdapterClassTwo implements \Bar\MyInterface
{
    // ...
}
<?php

namespace Services;

final class MyService
{

         public function __construct(private \Bar\MyInterface $one) //MyAdapterClassOne class is injected
          {
          }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.