Change record status: 
Project: 
Introduced in branch: 
11.2.x
Introduced in version: 
11.2.0
Description: 

The cron service is no longer marked lazy, and its proxy Drupal\Core\ProxyClass\Cron has been removed. Instead, if cron needs to be injected into a service, it is recommended to use service closures instead.

If existing code injecting the cron service is not updated, there may be a slight performance hit due to the different ways that lazy services/proxy classes and service closures optimize for late instantiation (generally 1ms or less). Otherwise, existing code should continue to function as usual.

Before:

public function __construct(
  protected CronInterface $cron,
) {}

Service definition:

services:
  my_service:
    class: Foo\Bar
    arguments: ['@cron']

After:

public function __construct(
  protected \Closure $cronClosure,
) {}

protected function getCron(): CronInterface {
  return ($this->cronClosure)();
}

Service definition:

services:
  my_service:
    class: Foo\Bar
    arguments: [!service_closure '@cron']

Service closures can also be autowired.
Before:

public function __construct(
  protected CronInterface $cron,
) {}

Service definition:

services:
  my_service:
    class: Foo\Bar
    autowire: true

After:

use Symfony\Component\DependencyInjection\Attribute\AutowireServiceClosure;

public function __construct(
  #[AutowireServiceClosure('cron')]
  protected \Closure $cronClosure,
) {}

protected function getCron(): CronInterface {
  return ($this->cronClosure)();
}
Impacts: 
Module developers