\Drupal()::getContainer() is marked as deprecated, but there is no obvious plan for what should be used instead or any effort to move away from it. In fact #2160655: Improve error handling of \Drupal class actually adds many more uses of it.
The docblock says "This method is only useful for the testing environment. It should not be used otherwise" but it is in fact widely used across core (not just in tests). Whatever we decide to do should presumably also apply to setContainer().
If we decide that these methods should not be used then we will need to remove usages of them, then prevent people from using them. I suggest marking these methods as protected, and adding public wrappers called get/setTestContainer (possibly in a subclass).
If we decide that these methods are OK to use, then we just need to update one docblock.
Comments
Comment #1
berdirThe @deprecate there is bogus, there's an existing issue to undeprecate it somewhere.
Comment #2
sunGiven #2182439: Provide a \Drupal::hasService() method, I think this method can be removed/deleted, so I'd re-purpose this issue to remove the method instead of "un-deprecating" it.
Comment #3
ianthomas_ukDuplicate of #2061761: Mark Drupal::getContainer() as internal, thanks Berdir