diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php
index ed50735..71256cb 100644
--- a/core/lib/Drupal/Core/Config/ConfigImporter.php
+++ b/core/lib/Drupal/Core/Config/ConfigImporter.php
@@ -788,9 +788,6 @@ protected function processExtension($type, $op, $name) {
       ->setSourceStorage($this->storageComparer->getSourceStorage());
     if ($type == 'module') {
       $this->moduleInstaller->$op(array($name), FALSE);
-      // Installing a module can cause a kernel boot therefore reinject all the
-      // services.
-      $this->reInjectMe();
       // During a module install or uninstall the container is rebuilt and the
       // module handler is called from drupal_get_complete_schema(). This causes
       // the container's instance of the module handler not to have loaded all
@@ -1035,21 +1032,4 @@ public function alreadyImporting() {
     return !$this->lock->lockMayBeAvailable(static::LOCK_NAME);
   }
 
-  /**
-   * Gets all the service dependencies from \Drupal.
-   *
-   * Since the ConfigImporter handles module installation the kernel and the
-   * container can be rebuilt and altered during processing. It is necessary to
-   * keep the services used by the importer in sync.
-   */
-  protected function reInjectMe() {
-    $this->_serviceIds = array();
-    $vars = get_object_vars($this);
-    foreach ($vars as $key => $value) {
-      if (is_object($value) && isset($value->_serviceId)) {
-        $this->$key = \Drupal::service($value->_serviceId);
-      }
-    }
-  }
-
 }
diff --git a/core/lib/Drupal/Core/CoreServiceProvider.php b/core/lib/Drupal/Core/CoreServiceProvider.php
index 8244320..1dba4c5 100644
--- a/core/lib/Drupal/Core/CoreServiceProvider.php
+++ b/core/lib/Drupal/Core/CoreServiceProvider.php
@@ -93,8 +93,6 @@ public function register(ContainerBuilder $container) {
 
     // Register plugin managers.
     $container->addCompilerPass(new PluginManagerPass());
-
-    $container->addCompilerPass(new DependencySerializationTraitPass());
   }
 
   /**
diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/DependencySerializationTraitPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/DependencySerializationTraitPass.php
deleted file mode 100644
index 2bb0b70..0000000
--- a/core/lib/Drupal/Core/DependencyInjection/Compiler/DependencySerializationTraitPass.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\Core\DependencyInjection\Compiler\DependencySerializationTraitPass.
- */
-
-namespace Drupal\Core\DependencyInjection\Compiler;
-
-use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-
-/**
- * Sets the _serviceId property on all services.
- *
- * @see \Drupal\Core\DependencyInjection\DependencySerializationTrait
- */
-class DependencySerializationTraitPass implements CompilerPassInterface {
-
-  /**
-   * {@inheritdoc}
-   */
-  public function process(ContainerBuilder $container) {
-    foreach ($container->getDefinitions() as $service_id => $definition) {
-      // Only add the property to services that are public (as private services
-      // can not be reloaded through Container::get()) and are objects.
-      if (!$definition->hasTag('parameter_service') && $definition->isPublic()) {
-        $definition->setProperty('_serviceId', $service_id);
-      }
-    }
-  }
-
-}
diff --git a/core/lib/Drupal/Core/DependencyInjection/Container.php b/core/lib/Drupal/Core/DependencyInjection/Container.php
index 4e28d54..c18871a 100644
--- a/core/lib/Drupal/Core/DependencyInjection/Container.php
+++ b/core/lib/Drupal/Core/DependencyInjection/Container.php
@@ -12,19 +12,9 @@
 /**
  * Extends the symfony container to set the service ID on the created object.
  */
-class Container extends SymfonyContainer {
+class Container extends SymfonyContainer implements SleepHelperInterface {
 
-  /**
-   * {@inheritdoc}
-   */
-  public function set($id, $service, $scope = SymfonyContainer::SCOPE_CONTAINER) {
-     parent::set($id, $service, $scope);
-
-    // Ensure that the _serviceId property is set on synthetic services as well.
-    if (isset($this->services[$id]) && is_object($this->services[$id]) && !isset($this->services[$id]->_serviceId)) {
-      $this->services[$id]->_serviceId = $id;
-    }
-  }
+  use SleepHelperTrait;
 
   /**
    * {@inheritdoc}
diff --git a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
index ce692b5..53181fb 100644
--- a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
+++ b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
@@ -19,7 +19,9 @@
  *
  * @ingroup container
  */
-class ContainerBuilder extends SymfonyContainerBuilder {
+class ContainerBuilder extends SymfonyContainerBuilder implements SleepHelperInterface {
+
+  use SleepHelperTrait;
 
   /**
    * {@inheritdoc}
@@ -45,11 +47,6 @@ public function set($id, $service, $scope = self::SCOPE_CONTAINER) {
       throw new \InvalidArgumentException("Service ID names must be lowercase: $id");
     }
     SymfonyContainer::set($id, $service, $scope);
-
-    // Ensure that the _serviceId property is set on synthetic services as well.
-    if (isset($this->services[$id]) && is_object($this->services[$id]) && !isset($this->services[$id]->_serviceId)) {
-      $this->services[$id]->_serviceId = $id;
-    }
   }
 
   /**
diff --git a/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php b/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php
index cb6a27d..26624a1 100644
--- a/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php
+++ b/core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php
@@ -25,22 +25,38 @@
    * {@inheritdoc}
    */
   public function __sleep() {
-    $this->_serviceIds = array();
     $vars = get_object_vars($this);
-    foreach ($vars as $key => $value) {
-      if (is_object($value) && isset($value->_serviceId)) {
-        // If a class member was instantiated by the dependency injection
-        // container, only store its ID so it can be used to get a fresh object
-        // on unserialization.
-        $this->_serviceIds[$key] = $value->_serviceId;
-        unset($vars[$key]);
-      }
-      // Special case the container, which might not have a service ID.
-      elseif ($value instanceof ContainerInterface) {
-        $this->_serviceIds[$key] = 'service_container';
-        unset($vars[$key]);
+    try {
+      $container = \Drupal::getContainer();
+      if ($container instanceof SleepHelperInterface) {
+        $hashes = $container->getHashes();
+        foreach ($vars as $key => $value) {
+          if (is_object($value)) {
+            $service_id = FALSE;
+            // Special case the container.
+            if ($value instanceof ContainerInterface) {
+              $service_id = 'service_container';
+            }
+            else {
+              $hash = spl_object_hash($value);
+              if (isset($hashes[$hash])) {
+                $service_id = $hashes[$hash];
+              }
+            }
+            if ($service_id) {
+              // If a class member was instantiated by the dependency injection
+              // container, only store its ID so it can be used to get a fresh object
+              // on unserialization.
+              $this->_serviceIds[$key] = $service_id;
+              unset($vars[$key]);
+            }
+          }
+        }
       }
     }
+    catch (ContainerNotInitializedException $e) {
+      // No container, no problem.
+    }
 
     return array_keys($vars);
   }
diff --git a/core/lib/Drupal/Core/DependencyInjection/SleepHelperInterface.php b/core/lib/Drupal/Core/DependencyInjection/SleepHelperInterface.php
new file mode 100644
index 0000000..b7fab8c
--- /dev/null
+++ b/core/lib/Drupal/Core/DependencyInjection/SleepHelperInterface.php
@@ -0,0 +1,21 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\DependencyInjection\SleepHelperInterface.
+ */
+
+
+namespace Drupal\Core\DependencyInjection;
+
+interface SleepHelperInterface {
+
+  /**
+   * Get the SPL hashes of the services.
+   *
+   * When sleeping an object it becomes possible to investigate whether its
+   * properties are services.
+   */
+  public function getHashes();
+
+}
diff --git a/core/lib/Drupal/Core/DependencyInjection/SleepHelperTrait.php b/core/lib/Drupal/Core/DependencyInjection/SleepHelperTrait.php
new file mode 100644
index 0000000..02ec6dd
--- /dev/null
+++ b/core/lib/Drupal/Core/DependencyInjection/SleepHelperTrait.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * @file
+ * Contains
+ */
+
+namespace Drupal\Core\DependencyInjection;
+
+/**
+ * Collects the service hashes to help __sleep().
+ *
+ * @see Drupal\Core\DependencyInjection\DependencySerializationTrait
+ */
+trait SleepHelperTrait {
+
+  protected $hashes = [];
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getHashes() {
+    foreach ($this->services as $id => $service) {
+      if (is_object($service)) {
+        $this->hashes[spl_object_hash($service)] = $id;
+      }
+    }
+    return $this->hashes;
+  }
+
+  /**
+   * Store hashes from a previous container.
+   *
+   * @param array $hashes
+   */
+  public function setHashes(array $hashes) {
+    $this->hashes = $hashes;
+  }
+
+}
diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index 6a5ce77..d646f74 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -755,6 +755,8 @@ protected function initializeContainer() {
       if ($this->container->initialized('current_user')) {
         $current_user_id = $this->container->get('current_user')->id();
       }
+      // Save the current hashes.
+      $hashes = $this->container->getHashes();
 
       // If there is a session, close and save it.
       if ($this->container->initialized('session')) {
@@ -806,6 +808,9 @@ protected function initializeContainer() {
       }
     }
 
+    if (!empty($hashes)) {
+      $container->setHashes($hashes);
+    }
     if (!empty($current_user_id)) {
       $this->container->get('current_user')->setInitialAccountId($current_user_id);
     }
diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php
index 73b32ec..1a2984a 100644
--- a/core/modules/system/src/Form/ModulesListForm.php
+++ b/core/modules/system/src/Form/ModulesListForm.php
@@ -103,6 +103,13 @@ class ModulesListForm extends FormBase {
   protected $permissionHandler;
 
   /**
+   * The access manager.
+   *
+   * @var \Drupal\Core\Access\AccessManagerInterface
+   */
+  protected $accessManager;
+
+  /**
    * {@inheritdoc}
    */
   public static function create(ContainerInterface $container) {
diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php
index 0df17c4..de0abe0 100644
--- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php
+++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php
@@ -29,28 +29,6 @@ public function testGet() {
   }
 
   /**
-   * @covers ::set
-   */
-  public function testSet() {
-    $container = new ContainerBuilder();
-    $class = new BarClass();
-    $container->set('bar', $class);
-    $this->assertEquals('bar', $class->_serviceId);
-  }
-
-  /**
-   * @covers ::set
-   * @expectedException \InvalidArgumentException
-   * @expectedExceptionMessage Service ID names must be lowercase: Bar
-   */
-  public function testSetException() {
-    $container = new ContainerBuilder();
-    $class = new BarClass();
-    $container->set('Bar', $class);
-    $this->assertNotEquals('bar', $class->_serviceId);
-  }
-
-  /**
    * @covers ::setParameter
    * @expectedException \InvalidArgumentException
    * @expectedExceptionMessage Parameter names must be lowercase: Buzz
diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php
index 377f7be..3c88a0f 100644
--- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php
+++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php
@@ -28,14 +28,14 @@ public function testSerialize() {
   }
 
   /**
-   * @covers ::set
+   * @covers ::getHashes
    */
-  public function testSet() {
+  public function testGetHashes() {
     $container = new Container();
-    $class = new BarClass();
-    $container->set('bar', $class);
-    // Ensure that _serviceId is set on the object.
-    $this->assertEquals('bar', $class->_serviceId);
+    $service = new BarClass();
+    $container->set('bar', $service);
+    // Ensure the right hashes are returned.
+    $this->assertEquals([spl_object_hash($service) => 'bar'], $container->getHashes());
   }
 
 }
diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/DependencySerializationTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/DependencySerializationTest.php
index ad05400..bd7fe01 100644
--- a/core/tests/Drupal/Tests/Core/DependencyInjection/DependencySerializationTest.php
+++ b/core/tests/Drupal/Tests/Core/DependencyInjection/DependencySerializationTest.php
@@ -26,7 +26,6 @@ class DependencySerializationTest extends UnitTestCase {
   public function testSerialization() {
     // Create a pseudo service and dependency injected object.
     $service = new \stdClass();
-    $service->_serviceId = 'test_service';
     $container = new Container();
     $container->set('test_service', $service);
     $container->set('service_container', $container);
