Problem/Motivation

Currently, some public services are not easily autowireable because their service IDs do not match their class names or required aliases are missing. This discrepancy makes constructor-based dependency injection less straightforward for module and custom code developers, as autowiring only works when the container can resolve dependencies by class name or alias.

Steps to reproduce

  • Create aliases for all relevant public services.
  • These aliases should match the class name, enabling seamless autowiring via type-hinting in constructors and other methods.
  • This change will allow developers to use auto-wiring for these services without additional configuration, reducing boilerplate and improving DX.

Example
For a service defined as (in acquia_dam.services.yml):

  acquia_dam.authentication_service:
    class: Drupal\acquia_dam\AcquiadamAuthService
    arguments: ['@user.data', '@config.factory', '@http_client', '@state', '@module_handler', '@logger.channel.acquia_dam', '@cache_tags.invalidator', '@logger.channel.acquia_dam', '@?key.repository']

Add an alias:
Drupal\acquia_dam\AcquiadamAuthService: '@acquia_dam.authentication_service'

Benefits

  • Enables Symfony/Drupal autowiring for these services by class name.
  • Removes the need for explicit service IDs in arguments or factories, improving readability and maintainability.
  • Aligns with modern Symfony practices and recommended service configuration.

Issue fork acquia_dam-3559554

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

rajeshreeputra created an issue. See original summary.

rajeshreeputra’s picture

Status: Active » Needs work
rajeshreeputra’s picture

Assigned: Unassigned » rajeshreeputra
rajeshreeputra’s picture

Status: Needs work » Needs review

Requesting review.

rajeshreeputra changed the visibility of the branch 3559554-create-service-aliases to hidden.

rohan-sinha’s picture

Status: Needs review » Reviewed & tested by the community

lgtm.

rajeshreeputra’s picture

Status: Reviewed & tested by the community » Needs work

The MR targets the 1.2.x branch; we need it for the 1.1.x branch. Moving it back in needs work.

rajeshreeputra’s picture

Status: Needs work » Needs review

Resolved conflicts and rebased the MR!280 that targets 1.1.x branch, closed MR!230.
Requesting review.

  • rajeshreeputra committed e5119569 on 1.1.x
    Resolve #3559554 "Create service aliases for public services to improve...
rajeshreeputra’s picture

Status: Needs review » Fixed

MR merged!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.