Skip to content

[DependencyInjection] Support local interface/class bindings #22167

@GuilhemN

Description

@GuilhemN
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes
Symfony version 3.3 ? probably 3.4

A great idea came out on Slack about local bindings.
We could allow injecting services based on type hints on a per service/file basis:

services:
    _defaults:
        bindings:
            BarInterface: '@alternative_bar'

    Foo:
        bindings:
            BarInterface: '@bar'
            $quz: 'quzvalue'

This way, @bar will be injected in any parameter type hinted as BarInterface (in a constructor or a method signature), but only for this service/file.
Note that bindings could be unused, giving a better solution than #22152 to #21711.

As named parameters are usable in arguments, bindings could be too:

services:
    Foo:
        arguments:
            BarInterface: '@bar'

ping @nicolas-grekas, @lunetics

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