Skip to content

[DI] [DX] Default service tag configuration causes confusion #22497

@curry684

Description

@curry684
Q A
Bug report? no
Feature request? possibly
BC Break report? no
RFC? yes
Symfony version master

I just created a service definition file like this SCCEE:

services:
    _defaults:
        tags:           [ { name: kernel.event_subscriber } ]

    some.event.subscriber:
        calls:
            - [setLogger, ["@logger"]]
        tags:           [ { name: monolog.logger, channel: specific_channel } ]

And then spent half an hour debugging why my events weren't being processed.

The reasoning is sound of course - I provided a default, and then I provided a real value overwriting the default. It's however not intuitive and imho highly confusing that this doesn't work like this out of the box.

I see 2 solutions to this:

  1. Merge tags by default based on name. Seems to make sense but it may go wrong in edge cases I'm not seeing.
  2. If a 'mergeable' property like tags is provided both in default/instanceof and definition, require setting a property in the like merge_tags explicitly to true or false, and bail out if it isn't set.

Comments?

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