profileRyan KesPGP keyI build stuffEmailGithubTwitterLast.fmMastodonMatrix

Autowiring By Type and Name

Introduction

Since Symfony 4.2, services can now be bound by type and name.

Syntax

# config/services.yaml
services:
  _defaults:
    bind:
      # it works with scalar types too (string, int, array, etc.)
      string $adminEmail: "manager@example.com"

      # but it's mostly used with classes
      Psr\Log\LoggerInterface $requestLogger: "@monolog.logger.request"