10000 [DependencyInjection] when@dev does not inherit defaults + autoconfigure does not work · Issue #46803 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[DependencyInjection] when@dev does not inherit defaults + autoconfigure does not work #46803
Closed
@lyrixx

Description

@lyrixx

Hello

I faced something strange.
I wanted to add a data collector on a service. So I made a decorator.

My initial file:

services:
    _defaults:
        autowire: true
        autoconfigure: true

    AppBundle\AgentProxy\:
        resource: '../../../src/AgentProxy/*'
        exclude:
            - '../../../src/AgentProxy/**/Exception/*'
            - '../../../src/AgentProxy/**/Model/*'

    AppBundle\AgentProxy\ClientInterface: '@AppBundle\AgentProxy\Client'

So I blindly added

when@dev:
    services:
        AppBundle\AgentProxy\ClientCollector:
            decorates: AppBundle\AgentProxy\ClientInterface

It does not work for 2 reasons

  1. Autowire does not work even if it's in the same file. I need to add _defaults: { autowire: true} in the when@dev section
  2. So I also added autoconfigure: true, but does not work. I need to manually tag the service.
The final configuration that works
services:
    _defaults:
        autowire: true
        autoconfigure: true

    AppBundle\AgentProxy\:
        resource: '../../../src/AgentProxy/*'
        exclude:
            - '../../../src/AgentProxy/**/Exception/*'
            - '../../../src/AgentProxy/**/Model/*'

    AppBundle\AgentProxy\ClientInterface: '@AppBundle\AgentProxy\Client'

when@dev:
    services:
        _defaults:
            autowire: true
            autoconfigure: true # useless

        AppBundle\AgentProxy\ClientCollector:
            decorates: AppBundle\AgentProxy\ClientInterface
            tags:
                -
                    name: data_collector
                    id: 'AppBundle\AgentProxy\ClientCollector'

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

      0