Support 'bind' in service container

Created on 20 July 2023, over 1 year ago
Updated 27 June 2024, 5 months ago

Problem/Motivation

The symfony service container allows to put a "bind" key in https://symfony.com/doc/current/service_container.html#binding-arguments...

Currently this is not enabled in Drupal.

It would solve a similar purpose as the global aliases described in πŸ“Œ [policy] Service autowiring - decide approach for multiple service implementations based on the same class and different arguments Needs work .
But instead of a global mapping, it binds only the services within a single *.services.yml file.
This way, a module can bind its own instance(s) of logger or other services, without side effects on core or other modules.

Steps to reproduce

In a *.container.yml file, do this:

services:
    _defaults:
        bind:
            # pass this service for any LoggerInterface type-hint for any
            # service that's defined in this file
            Psr\Log\LoggerInterface: '@logger.channel.mymodule'
    logger.channel.mymodule:
        parent: logger.channel_base
        arguments: ['mymodule']

(to be continued)

Proposed resolution

Enable the bind key.
Write tests.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated about 4 hours ago

Created by

πŸ‡©πŸ‡ͺGermany donquixote

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024