Skip to content

Extend #[AsAlias] to arguments #60158

Open
@gaizkaeu

Description

@gaizkaeu

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