Set parent service when registering a service in a ServiceProvider I want to create dynamic services, therefore I added a ServiceProvider class to my module.

I have created a base service that my other services will have as parent.

When doing this in my_module.services.yml, I can just use:

parent: service_name


But I can't find out how to do in the ServiceProvider class.

My class looks like this:

class MyModuleServiceProvider extends ServiceProviderBase {

  /**
   * {@inheritDoc}
   */
  public function register(ContainerBuilder $container) {
    // Create services for our base normalizer classes.
    $container-&gt;register('MY_MODULE_rest.entity_normalizer_base', EntityNormalizerBase::class)
      -&gt;addArgument(new Reference('entity_type.manager'));

    // Create node normalizer service.
    $container-&gt;register('MY_MODULE_rest.node_normalizer', NodeNormalizer::class)
      -&gt;addTag('normalizer', ['priority' =&gt; 1])
      // How can I set "MY_MODULE_rest.entity_normalizer_base" as the parent for this one?
      -&gt;addArgument(new Reference('path_alias.manager'))
      -&gt;addArgument(new Reference('language_manager'));
  }
}
You can find your answer in the symfony docs, How to Manage Common Dependencies with Parent Services. In the third snippet we see:

use AppBundle\Repository\BaseDoctrineRepository;
use AppBundle\Repository\DoctrinePostRepository;
use AppBundle\Repository\DoctrineUserRepository;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Reference;

$container-&gt;register(BaseDoctrineRepository::class)
    -&gt;setAbstract(true)
    -&gt;addArgument(new Reference('doctrine.orm.entity_manager'))
    -&gt;addMethodCall('setLogger', [new Reference('logger')]);

// extend the AppBundle\Repository\BaseDoctrineRepository service
$definition = new ChildDefinition(BaseDoctrineRepository::class);
$definition-&gt;setClass(DoctrineUserRepository::class);
$container-&gt;setDefinition(DoctrineUserRepository::class, $definition);


Looking at the docs and your code, my understanding is you'd do something like:

use Symfony\Component\DependencyInjection\ChildDefinition;

class MyModuleServiceProvider extends ServiceProviderBase {

  /**
   * {@inheritDoc}
   */
  public function register(ContainerBuilder $container) {
    // Create services for our base normalizer classes.
    $container-&gt;register('MY_MODULE_rest.entity_normalizer_base', EntityNormalizerBase::class)
      -&gt;addArgument(new Reference('entity_type.manager'));

    $node_definition = new ChildDefinition('MY_MODULE_rest.entity_normalizer_base');
    $node_definition-&gt;setClass(NodeNormalizer::class);
    $node_definition-&gt;addTag('normalizer', ['priority' =&gt; 1]);
    $node_definition-&gt;addArgument(new Reference('path_alias.manager'));
    $node_definition-&gt;addArgument(new Reference('language_manager'));

    // Create node normalizer service.
    $container-&gt;setDefinition('MY_MODULE_rest.node_normalizer', $node_definition)

  }
}