diff --git a/core/core.services.yml b/core/core.services.yml
index 6b8334a..5583040 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -173,7 +173,7 @@ services:
     arguments: [default]
   form_builder:
     class: Drupal\Core\Form\FormBuilder
-    arguments: ['@form_validator', '@form_submitter', '@form_cache', '@module_handler', '@event_dispatcher', '@request_stack', '@class_resolver', '@theme.manager', '@?csrf_token', '@?http_kernel']
+    arguments: ['@form_validator', '@form_submitter', '@form_cache', '@module_handler', '@event_dispatcher', '@request_stack', '@class_resolver', '@theme.manager', '@?csrf_token', '@?kernel']
   form_validator:
     class: Drupal\Core\Form\FormValidator
     arguments: ['@request_stack', '@string_translation', '@csrf_token', '@logger.channel.form']
diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php
index 0a9849d..3fb114b 100644
--- a/core/lib/Drupal/Core/Config/ConfigImporter.php
+++ b/core/lib/Drupal/Core/Config/ConfigImporter.php
@@ -530,7 +530,6 @@ public function initialize() {
     // We have extensions to process.
     if ($this->totalExtensionsToProcess > 0) {
       $sync_steps[] = 'processExtensions';
-      $sync_steps[] = 'flush';
     }
     $sync_steps[] = 'processConfigurations';
 
@@ -541,20 +540,6 @@ public function initialize() {
   }
 
   /**
-   * Flushes Drupal's caches.
-   */
-  public function flush(array &$context) {
-    // Rebuild the container and flush Drupal's caches. If the container is not
-    // rebuilt first the entity types are not discovered correctly due to using
-    // an entity manager that has the incorrect container namespaces injected.
-    \Drupal::service('kernel')->rebuildContainer(TRUE);
-    drupal_flush_all_caches();
-    $this->reInjectMe();
-    $context['message'] = $this->t('Flushed all caches.');
-    $context['finished'] = 1;
-  }
-
-  /**
    * Processes extensions as a batch operation.
    *
    * @param array $context.
@@ -1014,21 +999,4 @@ public function alreadyImporting() {
     return !$this->lock->lockMayBeAvailable(static::LOCK_ID);
   }
 
-  /**
-   * 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->eventDispatcher = \Drupal::service('event_dispatcher');
-    $this->configManager = \Drupal::service('config.manager');
-    $this->lock = \Drupal::lock();
-    $this->typedConfigManager = \Drupal::service('config.typed');
-    $this->moduleHandler = \Drupal::moduleHandler();
-    $this->themeHandler = \Drupal::service('theme_handler');
-    $this->stringTranslation = \Drupal::service('string_translation');
-  }
-
 }
diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php
index 428ca2a..727ab68 100644
--- a/core/lib/Drupal/Core/Extension/ModuleHandler.php
+++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php
@@ -810,8 +810,9 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
         // Now install the module's schema if necessary.
         drupal_install_schema($module);
 
-        // Clear plugin manager caches.
+        // Clear plugin manager caches and flag router to rebuild if requested.
         \Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions();
+        \Drupal::service('router.builder')->setRebuildNeeded();
 
         // Set the schema version to the number of the last update provided by
         // the module, or the minimum core schema version.
@@ -999,7 +1000,9 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
       // its statically cached list.
       drupal_static_reset('system_rebuild_module_data');
 
+      // Clear plugin manager caches and flag router to rebuild if requested.
       \Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions();
+      \Drupal::service('router.builder')->setRebuildNeeded();
 
       // Update the kernel to exclude the uninstalled modules.
       \Drupal::service('kernel')->updateModules($module_filenames, $module_filenames);
@@ -1022,8 +1025,6 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
     // Let other modules react.
     $this->invokeAll('modules_uninstalled', array($module_list));
 
-    drupal_flush_all_caches();
-
     return TRUE;
   }
 
diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php
index 6fb6467..ebab63f 100644
--- a/core/lib/Drupal/Core/Form/FormBuilder.php
+++ b/core/lib/Drupal/Core/Form/FormBuilder.php
@@ -14,6 +14,7 @@
 use Drupal\Component\Utility\UrlHelper;
 use Drupal\Core\Access\CsrfTokenGenerator;
 use Drupal\Core\DependencyInjection\ClassResolverInterface;
+use Drupal\Core\DrupalKernelInterface;
 use Drupal\Core\Extension\ModuleHandlerInterface;
 use Drupal\Core\Render\Element;
 use Drupal\Core\Site\Settings;
@@ -61,11 +62,15 @@ class FormBuilder implements FormBuilderInterface, FormValidatorInterface, FormS
   protected $csrfToken;
 
   /**
-   * The HTTP kernel to handle forms returning response objects.
+   * The kernel to handle forms returning response objects.
    *
-   * @var \Symfony\Component\HttpKernel\HttpKernel
+   * Explicitly use the DrupalKernel as that is consistent with index.php for
+   * terminating the request and in case someone rebuilds the container,
+   * this kernel is synthetic and always points to the new container.
+   *
+   * @var \Drupal\Core\DrupalKernelInterface
    */
-  protected $httpKernel;
+  protected $kernel;
 
   /**
    * The class resolver.
@@ -126,10 +131,10 @@ class FormBuilder implements FormBuilderInterface, FormValidatorInterface, FormS
    *   The theme manager.
    * @param \Drupal\Core\Access\CsrfTokenGenerator $csrf_token
    *   The CSRF token generator.
-   * @param \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel
-   *   The HTTP kernel.
+   * @param \Drupal\Core\DrupalKernelInterface $kernel
+   *   The kernel.
    */
-  public function __construct(FormValidatorInterface $form_validator, FormSubmitterInterface $form_submitter, FormCacheInterface $form_cache, ModuleHandlerInterface $module_handler, EventDispatcherInterface $event_dispatcher, RequestStack $request_stack, ClassResolverInterface $class_resolver, ThemeManagerInterface $theme_manager, CsrfTokenGenerator $csrf_token = NULL, HttpKernelInterface $http_kernel = NULL) {
+  public function __construct(FormValidatorInterface $form_validator, FormSubmitterInterface $form_submitter, FormCacheInterface $form_cache, ModuleHandlerInterface $module_handler, EventDispatcherInterface $event_dispatcher, RequestStack $request_stack, ClassResolverInterface $class_resolver, ThemeManagerInterface $theme_manager, CsrfTokenGenerator $csrf_token = NULL, DrupalKernelInterface $kernel = NULL) {
     $this->formValidator = $form_validator;
     $this->formSubmitter = $form_submitter;
     $this->formCache = $form_cache;
@@ -138,7 +143,7 @@ public function __construct(FormValidatorInterface $form_validator, FormSubmitte
     $this->requestStack = $request_stack;
     $this->classResolver = $class_resolver;
     $this->csrfToken = $csrf_token;
-    $this->httpKernel = $http_kernel;
+    $this->kernel = $kernel;
     $this->themeManager = $theme_manager;
   }
 
@@ -1075,14 +1080,14 @@ protected function buttonWasClicked($element, FormStateInterface &$form_state) {
    */
   protected function sendResponse(Response $response) {
     $request = $this->requestStack->getCurrentRequest();
-    $event = new FilterResponseEvent($this->httpKernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
+    $event = new FilterResponseEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
 
     $this->eventDispatcher->dispatch(KernelEvents::RESPONSE, $event);
     // Prepare and send the response.
     $event->getResponse()
       ->prepare($request)
       ->send();
-    $this->httpKernel->terminate($request, $response);
+    $this->kernel->terminate($request, $response);
   }
 
   /**
diff --git a/core/modules/config/src/Form/ConfigSync.php b/core/modules/config/src/Form/ConfigSync.php
index f73de96..9edfab6 100644
--- a/core/modules/config/src/Form/ConfigSync.php
+++ b/core/modules/config/src/Form/ConfigSync.php
@@ -396,7 +396,6 @@ public static function finishBatch($success, $results, $operations) {
       $message = \Drupal::translation()->translate('An error occurred while processing %error_operation with arguments: @arguments', array('%error_operation' => $error_operation[0], '@arguments' => print_r($error_operation[1], TRUE)));
       drupal_set_message($message, 'error');
     }
-    drupal_flush_all_caches();
   }
 
 
diff --git a/core/modules/system/src/Form/ModulesListConfirmForm.php b/core/modules/system/src/Form/ModulesListConfirmForm.php
index df7dfef..c04a030 100644
--- a/core/modules/system/src/Form/ModulesListConfirmForm.php
+++ b/core/modules/system/src/Form/ModulesListConfirmForm.php
@@ -147,7 +147,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
     // Gets module list after install process, flushes caches and displays a
     // message if there are changes.
     if ($before != $this->moduleHandler->getModuleList()) {
-      drupal_flush_all_caches();
       drupal_set_message($this->t('The configuration options have been saved.'));
     }
 
diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php
index c1b2b73..23505fa 100644
--- a/core/modules/system/src/Form/ModulesListForm.php
+++ b/core/modules/system/src/Form/ModulesListForm.php
@@ -511,7 +511,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
     // Gets module list after install process, flushes caches and displays a
     // message if there are changes.
     if ($before != $this->moduleHandler->getModuleList()) {
-      drupal_flush_all_caches();
       drupal_set_message(t('The configuration options have been saved.'));
     }
   }
diff --git a/core/modules/system/src/Tests/Routing/RouterTest.php b/core/modules/system/src/Tests/Routing/RouterTest.php
index 05f86f7..4fd44bf 100644
--- a/core/modules/system/src/Tests/Routing/RouterTest.php
+++ b/core/modules/system/src/Tests/Routing/RouterTest.php
@@ -8,6 +8,7 @@
 namespace Drupal\system\Tests\Routing;
 
 use Drupal\simpletest\WebTestBase;
+use Symfony\Component\Routing\Exception\RouteNotFoundException;
 
 /**
  * Functional class for the full integrated routing system.
@@ -189,9 +190,18 @@ public function testControllerResolutionAjax() {
   /**
    * Tests that routes no longer exist for a module that has been uninstalled.
    */
-  public function testRouterUninstall() {
+  public function testRouterUninstallInstall() {
     \Drupal::moduleHandler()->uninstall(array('router_test'));
-    $route_count = \Drupal::database()->query('SELECT COUNT(*) FROM {router} WHERE name = :route_name', array(':route_name' => 'router_test.1'))->fetchField();
-    $this->assertEqual(0, $route_count, 'All router_test routes have been removed on uninstall.');
+    try {
+      \Drupal::service('router.route_provider')->getRouteByName('router_test.1');
+      $this->fail('Route was delete on uninstall.');
+    }
+    catch (RouteNotFoundException $e) {
+      $this->pass('Route was delete on uninstall.');
+    }
+    // Install the module again.
+    \Drupal::moduleHandler()->install(array('router_test'));
+    $route = \Drupal::service('router.route_provider')->getRouteByName('router_test.1');
+    $this->assertNotNull($route, 'Route exists after module installation');
   }
 }
diff --git a/core/modules/system/src/Tests/System/ThemeTest.php b/core/modules/system/src/Tests/System/ThemeTest.php
index e1b091d..5078156 100644
--- a/core/modules/system/src/Tests/System/ThemeTest.php
+++ b/core/modules/system/src/Tests/System/ThemeTest.php
@@ -244,8 +244,6 @@ function testSwitchDefaultTheme() {
     $this->clickLink(t('Set as default'));
     $this->assertEqual(\Drupal::config('system.theme')->get('default'), 'bartik');
 
-    drupal_flush_all_caches();
-
     // Test the default theme on the secondary links (blocks admin page).
     $this->drupalGet('admin/structure/block');
     $this->assertText('Bartik(' . t('active tab') . ')', 'Default local task on blocks admin page is the default theme.');
diff --git a/core/tests/Drupal/Tests/Core/Form/FormTestBase.php b/core/tests/Drupal/Tests/Core/Form/FormTestBase.php
index 47b80b1..61c4f95 100644
--- a/core/tests/Drupal/Tests/Core/Form/FormTestBase.php
+++ b/core/tests/Drupal/Tests/Core/Form/FormTestBase.php
@@ -117,9 +117,9 @@
   protected $translationManager;
 
   /**
-   * @var \Symfony\Component\HttpKernel\HttpKernel|\PHPUnit_Framework_MockObject_MockObject
+   * @var \Drupal\Core\DrupalKernelInterface|\PHPUnit_Framework_MockObject_MockObject
    */
-  protected $httpKernel;
+  protected $kernel;
 
   /**
    * @var \PHPUnit_Framework_MockObject_MockObject|\Psr\Log\LoggerInterface
@@ -142,7 +142,7 @@ protected function setUp() {
     $this->csrfToken = $this->getMockBuilder('Drupal\Core\Access\CsrfTokenGenerator')
       ->disableOriginalConstructor()
       ->getMock();
-    $this->httpKernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernel')
+    $this->kernel = $this->getMockBuilder('\Drupal\Core\DrupalKernel')
       ->disableOriginalConstructor()
       ->getMock();
     $this->account = $this->getMock('Drupal\Core\Session\AccountInterface');
@@ -161,7 +161,7 @@ protected function setUp() {
       ->setMethods(array('batchGet', 'drupalInstallationAttempted'))
       ->getMock();
 
-    $this->formBuilder = new TestFormBuilder($this->formValidator, $this->formSubmitter, $this->formCache, $this->moduleHandler, $this->eventDispatcher, $this->requestStack, $this->classResolver, $this->themeManager, $this->csrfToken, $this->httpKernel);
+    $this->formBuilder = new TestFormBuilder($this->formValidator, $this->formSubmitter, $this->formCache, $this->moduleHandler, $this->eventDispatcher, $this->requestStack, $this->classResolver, $this->themeManager, $this->csrfToken, $this->kernel);
     $this->formBuilder->setCurrentUser($this->account);
   }
 
