Skip to content

AutoconfigureTag overrides Autoconfigure #58957

@Justinas-Jurciukonis

Description

@Justinas-Jurciukonis

Symfony version(s) affected

7.0

Description

Previously we had following configuration:

services:
    _instanceOf:
        App\Validation\Entity\ActiveRecordValidatorInterface:
             shared: false
             lazy: true
             tags: ['app.tag.validation']

This allowed us to get all validators and mark them non-shared.

I am migrating this configuration into PHP Attributes using this documentation. It states:

If you need more capabilities to autoconfigure instances of your base class like their laziness, their bindings or their calls for example, you may rely on the Autoconfigure attribute.

But it seems that order of PHP Attributes matter and AutoconfigureTag overrides any previous Autoconfigure attribute, even through AutoconfigureTag does not accept anything more than tag configuration

How to reproduce

use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;

#[
    Autoconfigure(lazy: true, shared: false),
    AutoconfigureTag(self::class),
]
interface ActiveRecordValidatorInterface

All services implementing this interface are shared and eager services (ReadOnlyValidator as example):

Screenshot 2024-11-21 at 10 59 14

But if I merge these attributes or switch them in place, than it becomes correct:

#[
    AutoconfigureTag(self::class),
    Autoconfigure(lazy: true, shared: false),
]

or

#[Autoconfigure(tags: [self::class], lazy: true, shared: false)]
Screenshot 2024-11-21 at 11 01 52

Possible Solution

No response

Additional Context

No response

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