It was suggested in #2503927: Convert ExtensionDiscovery to a service to turn ExtensionDiscovery into a service. I think it is not really suitable as such, and we should write something new instead.
The ExtensionDiscovery component has a number of issues. It is mutable (->setProfileDirectories()), it is big, it explicitly calls out to the environment for global state data, and it statically caches mutable objects.
Some of the problems can be fixed. E.g. adding the additional key [$this->root]
to the static cache, as in #2605654-48: Modify Drupal\Core\Extension\ExtensionDiscovery to allow for scanning multiple file systems, enabling vfsStream testing.
But beyond this, we probably need to leave some of the crappy behavior in place for existing components that are already depending on it. One of the flaws is the existence of a setProfileDirectories()
method, which makes this object mutable and thus not suitable as a service.
If a depending component already needs to be modified (to use a service instead of calling a constructor), it can as well use a different tool that does the job more reliably.
More details in the first comment, since this will change over time.