Registering services to the Drupal service container without a module
Drupal's service container for dependency injection allows modules to register services and parameters to the service container or alter and modify the service container.
Drupal's service container for dependency injection allows modules to register services and parameters to the service container or alter and modify the service container.
Last week I wrote about dependency injection anti-patterns in Drupal. These anti-patterns occur when your service's constructor has logic that interacts with the injected dependent services beyond assigning them to properties.
Whenever I have done an audit for a Drupal codebase, one of the first things I manually review and profile is dependency injection anti-patterns in custom code and any contributed modules used. The anti-pattern isn't for accessing services statically through \Drupal: service. These anti-patterns live within the class's __construct method.