getDefinition(ThirdPartyTypeManager::class); $usedKeys = []; foreach ($container->findTaggedServiceIds(self::TAG) as $id => $tags) { $taggedService = $container->getDefinition($id); // check forr keys already in use : $key = $taggedService->getClass()::getKey(); if (\in_array($key, $usedKeys)) { throw new \LogicException(sprintf("Tag with key \"%s\" is already in used", $key)); } $usedKeys[] = $key; // alter the service definition of manager $definition->addMethodCall('addProvider', [ new Reference($id) ]); } } }