The value object Drupal\Core\Cache\CacheableMetadata
uses the Drupal\Core\Cache\Cache
methods when merging with an other CacheableMetadata object. The mergeContexts
in de Cache class has a hard dependency on the container. This seems to be something that should explicitly be called by an other service instead of the hacky \Drupal::service()
way.
Proposed solution would be to just assert if the given contexts are strings and if we need more validation we could do this at an other level.