Change record status: 
Project: 
Introduced in branch: 
11.x
Introduced in version: 
11.5.0
Description: 

Container persistence is now managed through a new ContainerStorageInterface abstraction. The active implementation is provided as a new service in the bootstrap container and selected automatically based on the container_base_class setting. Sites that previously overrode $settings['bootstrap_container_definition'] need to ensure their definition includes the new storage services, or override the container_storage service to customise how the container is stored.

New services in the default bootstrap container

The following services are now part of DrupalKernel::$defaultBootstrapContainerDefinition:

settings
The \Drupal\Core\Site\Settings singleton. Other bootstrap services use this to read settings without depending on the not-yet-built main container.
container_storage
The active \Drupal\Core\DependencyInjection\ContainerStorageInterface implementation selected by \Drupal\Core\DependencyInjection\ContainerStorage\ContainerStorageFactory::create().
container_storage.cache
\Drupal\Core\DependencyInjection\ContainerStorage\CacheContainerStorage — the legacy implementation that serialises the container definition as a PHP array using OptimizedPhpArrayDumper and stores it in the cache.container cache bin.
container_storage.php_dumper
\Drupal\Core\DependencyInjection\ContainerStorage\PhpDumperContainerStorage — the new implementation that uses Symfony's PhpDumper to compile the container into a PHP class stored via php_storage.service_container.
php_storage.service_container
A \Drupal\Component\PhpStorage\PhpStorageInterface instance for the service_container storage bin. Provided via PhpStorageFactory::get('service_container').

Overriding the container storage

To replace the container storage entirely — for example, to use a custom persistence mechanism — override the container_storage service in $settings['bootstrap_container_definition'] in settings.php:

  $settings['bootstrap_container_definition']['services']['container_storage'] = [
    'class' => \MyModule\MyCustomContainerStorage::class,
    // Add any constructor arguments your class requires:
    // 'arguments' => ['@some_bootstrap_service'],
  ];

Your class must implement \Drupal\Core\DependencyInjection\ContainerStorageInterface.

Backward compatibility for existing bootstrap_container_definition overrides

If your $settings['bootstrap_container_definition'] does not declare any of the new storage services, Drupal will merge the missing services in automatically.

Impacts: 
Site builders, administrators, editors
Site templates, recipes and distribution developers