diff --git a/core/core.services.yml b/core/core.services.yml
index 1b0d520b2f0095ac34155ccdb3e78f1a89332b38..c369394ce7dbab329d4708c8b4e6841471337a36 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -221,6 +221,7 @@ services:
     arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@module_handler']
   lock:
     class: Drupal\Core\Lock\DatabaseLockBackend
+    arguments: ['@database']
   user.tempstore:
     class: Drupal\user\TempStoreFactory
     arguments: ['@database', '@lock']
diff --git a/core/lib/Drupal/Core/Lock/DatabaseLockBackend.php b/core/lib/Drupal/Core/Lock/DatabaseLockBackend.php
index eef63b4a8474eb1603351f866222d97f4427b015..f3cd8034f9fb383495c77b40e5c7fa4623873666 100644
--- a/core/lib/Drupal/Core/Lock/DatabaseLockBackend.php
+++ b/core/lib/Drupal/Core/Lock/DatabaseLockBackend.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\Core\Lock;
 
+use Drupal\Core\Database\Connection;
 use Drupal\Core\Database\IntegrityConstraintViolationException;
 
 /**
@@ -14,13 +15,24 @@
  */
 class DatabaseLockBackend extends LockBackendAbstract {
 
+  /**
+   * The database connection.
+   *
+   * @var \Drupal\Core\Database\Connection
+   */
+  protected $database;
+
   /**
    * Constructs a new DatabaseLockBackend.
+   *
+   * @param \Drupal\Core\Database\Connection $database
+   *   The database connection.
    */
-  public function __construct() {
+  public function __construct(Connection $database) {
     // __destruct() is causing problems with garbage collections, register a
     // shutdown function instead.
     drupal_register_shutdown_function(array($this, 'releaseAll'));
+    $this->database = $database;
   }
 
   /**
@@ -32,7 +44,7 @@ public function acquire($name, $timeout = 30.0) {
     $expire = microtime(TRUE) + $timeout;
     if (isset($this->locks[$name])) {
       // Try to extend the expiration of a lock we already acquired.
-      $success = (bool) db_update('semaphore')
+      $success = (bool) $this->database->update('semaphore')
         ->fields(array('expire' => $expire))
         ->condition('name', $name)
         ->condition('value', $this->getLockId())
@@ -50,7 +62,7 @@ public function acquire($name, $timeout = 30.0) {
       // We always want to do this code at least once.
       do {
         try {
-          db_insert('semaphore')
+          $this->database->insert('semaphore')
             ->fields(array(
               'name' => $name,
               'value' => $this->getLockId(),
@@ -81,7 +93,7 @@ public function acquire($name, $timeout = 30.0) {
    * Implements Drupal\Core\Lock\LockBackedInterface::lockMayBeAvailable().
    */
   public function lockMayBeAvailable($name) {
-    $lock = db_query('SELECT expire, value FROM {semaphore} WHERE name = :name', array(':name' => $name))->fetchAssoc();
+    $lock = $this->database->query('SELECT expire, value FROM {semaphore} WHERE name = :name', array(':name' => $name))->fetchAssoc();
     if (!$lock) {
       return TRUE;
     }
@@ -91,7 +103,7 @@ public function lockMayBeAvailable($name) {
       // We check two conditions to prevent a race condition where another
       // request acquired the lock and set a new expire time. We add a small
       // number to $expire to avoid errors with float to string conversion.
-      return (bool) db_delete('semaphore')
+      return (bool) $this->database->delete('semaphore')
         ->condition('name', $name)
         ->condition('value', $lock['value'])
         ->condition('expire', 0.0001 + $expire, '<=')
@@ -105,7 +117,7 @@ public function lockMayBeAvailable($name) {
    */
   public function release($name) {
     unset($this->locks[$name]);
-    db_delete('semaphore')
+    $this->database->delete('semaphore')
       ->condition('name', $name)
       ->condition('value', $this->getLockId())
       ->execute();
@@ -121,7 +133,7 @@ public function releaseAll($lock_id = NULL) {
       if (empty($lock_id)) {
         $lock_id = $this->getLockId();
       }
-      db_delete('semaphore')
+      $this->database->delete('semaphore')
         ->condition('value', $lock_id)
         ->execute();
     }
diff --git a/core/modules/system/lib/Drupal/system/Tests/Lock/LockUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/Lock/LockUnitTest.php
index b1666f3e83c3722f9d7a4b18eb37ae78d646e8ce..db5f9080954dcb363785793c1ca494e8995012c8 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Lock/LockUnitTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Lock/LockUnitTest.php
@@ -39,7 +39,7 @@ public static function getInfo() {
 
   public function setUp() {
     parent::setUp();
-    $this->lock = new DatabaseLockBackend();
+    $this->lock = new DatabaseLockBackend($this->container->get('database'));
     $this->installSchema('system', 'semaphore');
   }
 
diff --git a/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php b/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php
index 5fb54e31e73db43a8659ea6cd7be482d89610d31..bbdc3548b6eb75d168c976c532e6195d271fd204 100644
--- a/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php
+++ b/core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php
@@ -83,7 +83,7 @@ protected function tearDown() {
    */
   public function testUserTempStore() {
     // Create a key/value collection.
-    $factory = new TempStoreFactory(Database::getConnection(), new DatabaseLockBackend());
+    $factory = new TempStoreFactory(Database::getConnection(), new DatabaseLockBackend(Database::getConnection()));
     $collection = $this->randomName();
 
     // Create two mock users.