Change record status: 
Project: 
Introduced in branch: 
9.2.x
Introduced in version: 
9.2.0
Description: 

For Drupal 9 a deprecation will be issued if a service is manually created without specifying either private or public, this will be required from Drupal 10.0.0 onwards.

Services are created private as default in Symfony 5 and Drupal expects services to be public. Drupal 9 uses Symfony 4.4 and Drupal 10 will use Symfony > 5.4.

All services created from SOMEMODULE.services.yml are changed to public by default. Only services created like:

$container = \Drupal::getContainer();
$definition = new Definition(RouteProvider::class);
$container->setDefinition($id, $definition);

Will no longer be created as a public service. To create the service as public change the code to:

$container = \Drupal::getContainer();
$definition = new Definition(RouteProvider::class);
$definition->setPublic(TRUE);
$container->setDefinition($id, $definition);
Impacts: 
Module developers

Comments

julitroalves’s picture

I was facing a problem with this after updating my site from Drupal 9 to Drupal 10.
Just after adding the $definition->setPublic(TRUE); on my service the module turned to work again.