use Drupal\Core\DependencyInjection\ContainerBuilder; // Create a new container builder object $container = new ContainerBuilder(); // Add services to the container $container->register('my_service', 'My\Service\Class'); // Set the new container for the current request \Drupal::setContainer($container);In this example, we create a new container builder object, register a new service called "my_service" with the class "My\Service\Class", and then set the new container using the setContainer method. Package library: Drupal Core.