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\Settingssingleton. Other bootstrap services use this to read settings without depending on the not-yet-built main container. container_storage- The active
\Drupal\Core\DependencyInjection\ContainerStorageInterfaceimplementation 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 usingOptimizedPhpArrayDumperand stores it in thecache.containercache bin.container_storage.php_dumper\Drupal\Core\DependencyInjection\ContainerStorage\PhpDumperContainerStorage— the new implementation that uses Symfony'sPhpDumperto compile the container into a PHP class stored viaphp_storage.service_container.php_storage.service_container- A
\Drupal\Component\PhpStorage\PhpStorageInterfaceinstance for theservice_containerstorage bin. Provided viaPhpStorageFactory::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.