Support arguments binding by name or type in *.services.yml files

Created on 26 January 2023, about 2 years ago
Updated 1 February 2023, about 2 years ago

This seems to be a duplicate of #3108565: Update the Yaml file Loader functionality to simplify service configuration β†’

Problem/Motivation

Symfony DI allows arguments binding by name or type, using 'services/_defaults/bind' in a *.services.yml file.
https://symfony.com/doc/current/service_container.html#binding-arguments...
This already works in symfony/dependency-injection:4.4, which is used by Drupal 9.5.

However, in Drupal's DI, the 'bind' key is not supported.

It would be useful in Drupal, as pointed out by @longwave in this comment:
#3295542-3: Use logger channel services consistently, instead of the factory object β†’

The feature was almost added in πŸ“Œ Support _defaults key in service.yml files for public, tags and autowire settings Fixed , but then it was removed from the PR to keep the scope limited. I don't know if it ever really worked, perhaps it was just a stub.

Steps to reproduce

Create a module with a *.services.yml file like this:

services:
  _defaults:
    autowire: true
    bind:
      Psr\Log\LoggerInterface: '@logger.channel.mymodule'
      Drupal\Component\DependencyInjection\ContainerInterface: '@service_container'
      Drupal\Core\Config\ConfigFactoryInterface: '@config.factory'
      GuzzleHttp\ClientInterface: '@http_client'
  [..]

It currently won't work:

The configuration key "bind" cannot be used to define a default value in "modules/custom/poc_nextcloud/poc_nextcloud.services.yml". Allowed keys are "public", "tags", "autowire".

Proposed resolution

Support 'services/_defaults/bind' key in YamlFileLoader.
Backport to 9.5.x.

Note that part of this will become obsolete with πŸ“Œ Enable service autowiring by adding interface aliases to core service definitions Fixed .
However:

Remaining tasks

User interface changes

API changes

Arguments binding now supported in *.services.yml files.

Data model changes

Release notes snippet

Arguments binding now supported in *.services.yml files.
See https://symfony.com/doc/current/service_container.html#binding-arguments...

πŸ“Œ Task
Status

Closed: duplicate

Version

10.1 ✨

Component
BaseΒ  β†’

Last updated about 7 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