Change record status: 
Project: 
Introduced in branch: 
11.2.x
Introduced in version: 
11.2.0
Description: 

ModuleHandler::addModule and ModuleHandler::addProfile have been deprecated and will be removed in Drupal 12.

There is no direct replacement.
These methods do not gather OOP hooks as OOP hooks require a container rebuild.

Adding modules or profiles run time is not supported.

Before:

\Drupal::service('module_handler')->addModule(['module_name']);
\Drupal::service('module_handler')->addProfile('profile_name', $install_state['profiles']['profile_name']->getPath());

After:

\Drupal::service('module_installer')->install(['module_name']);
\Drupal::service('module_installer')->install('profile_name', $install_state['profiles']['profile_name']->getPath());
Impacts: 
Module developers
Site templates, recipes and distribution developers