Skip to content

Define alias with an attribute #41188

@garak

Description

@garak

Description

Scenario: you have a concrete class that implements an interface. Currently, you need to add an alias in your services configuration,
The idea is to avoid it with a new php8 attribute, that can be applied to the class.

Example

<?php

namespace Foo;

use Symfony\Component\DependencyInjection\Attribute\Alias;

#[Alias]
final class MyClass implements \Bar\MyInterface
{
    // ...
}

the following then can be avoided:

services:
    Bar\MyInterface: '@Foo\MyClass'

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