diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index fdcb01b..ad96a50 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -2467,7 +2467,12 @@ function drupal_container(Container $new_container = NULL, $rebuild = FALSE) {
 
     // Register the KeyValueStore factory.
     $container
-      ->register('keyvalue', 'Drupal\Core\KeyValueStore\KeyValueFactory');
+      ->register('keyvalue', 'Drupal\Core\KeyValueStore\KeyValueFactory')
+      ->addArgument(new Reference('service_container'));
+    $container
+      ->register('keyvalue.database', 'Drupal\Core\KeyValueStore\KeyValueDatabaseFactory');
+      // @TODO uncomment this when http://drupal.org/node/1811730 is in.
+      // ->addArgument(new Reference('database'));
   }
   return $container;
 }
diff --git a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php
index c837796..a2ab0b1 100644
--- a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php
+++ b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php
@@ -8,16 +8,13 @@
 namespace Drupal\Core\KeyValueStore;
 
 use Drupal\Core\Database\Query\Merge;
+use Drupal\Core\Database\Connection;
 
 /**
  * Defines a default key/value store implementation.
  *
  * This is Drupal's default key/value store implementation. It uses the database
  * to store key/value data.
- *
- * @todo This class still calls db_* functions directly because it's needed
- *   very early, pre-Container.  Once the early bootstrap dependencies are
- *   sorted out, consider using an injected database connection instead.
  */
 class DatabaseStorage extends StorageBase {
 
@@ -36,8 +33,9 @@ class DatabaseStorage extends StorageBase {
    * @param string $table
    *   The name of the SQL table to use, defaults to key_value.
    */
-  public function __construct($collection, $table = 'key_value') {
+  public function __construct($collection, Connection $connection, $table = 'key_value') {
     parent::__construct($collection);
+    $this->connection = $connection;
     $this->table = $table;
   }
 
@@ -47,7 +45,7 @@ public function __construct($collection, $table = 'key_value') {
   public function getMultiple(array $keys) {
     $values = array();
     try {
-      $result = db_query('SELECT name, value FROM {' . db_escape_table($this->table) . '} WHERE name IN (:keys) AND collection = :collection', array(':keys' => $keys, ':collection' => $this->collection))->fetchAllAssoc('name');
+      $result = $this->connection->query('SELECT name, value FROM {' . $this->connection->escapeTable($this->table) . '} WHERE name IN (:keys) AND collection = :collection', array(':keys' => $keys, ':collection' => $this->collection))->fetchAllAssoc('name');
       foreach ($keys as $key) {
         if (isset($result[$key])) {
           $values[$key] = unserialize($result[$key]->value);
@@ -66,7 +64,7 @@ public function getMultiple(array $keys) {
    * Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::getAll().
    */
   public function getAll() {
-    $result = db_query('SELECT name, value FROM {' . db_escape_table($this->table) . '} WHERE collection = :collection', array(':collection' => $this->collection));
+    $result = $this->connection->query('SELECT name, value FROM {' . $this->connection->escapeTable($this->table) . '} WHERE collection = :collection', array(':collection' => $this->collection));
     $values = array();
 
     foreach ($result as $item) {
@@ -81,7 +79,7 @@ public function getAll() {
    * Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::set().
    */
   public function set($key, $value) {
-    db_merge($this->table)
+    $this->connection->merge($this->table)
       ->key(array(
         'name' => $key,
         'collection' => $this->collection,
@@ -94,7 +92,7 @@ public function set($key, $value) {
    * Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::setIfNotExists().
    */
   public function setIfNotExists($key, $value) {
-    $result = db_merge($this->table)
+    $result = $this->connection->merge($this->table)
       ->insertFields(array(
         'collection' => $this->collection,
         'name' => $key,
@@ -112,7 +110,7 @@ public function setIfNotExists($key, $value) {
   public function deleteMultiple(array $keys) {
     // Delete in chunks when a large array is passed.
     do {
-      db_delete($this->table)
+      $this->connection->delete($this->table)
         ->condition('name', array_splice($keys, 0, 1000))
         ->condition('collection', $this->collection)
         ->execute();
diff --git a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php
index 0ce7934..e989470 100644
--- a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php
+++ b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php
@@ -7,8 +7,8 @@
 
 namespace Drupal\Core\KeyValueStore;
 
+use Drupal\Core\Database\Connection;
 use Drupal\Core\Database\Query\Merge;
-use Drupal\Core\Database\Database;
 
 /**
  * Defines a default key/value store implementation for expiring items.
@@ -51,10 +51,8 @@ class DatabaseStorageExpirable extends DatabaseStorage implements KeyValueStoreE
    *   - table: (optional) The name of the SQL table to use. Defaults to
    *     key_value_expire.
    */
-  public function __construct($collection, array $options = array()) {
-    parent::__construct($collection, $options);
-    $this->connection = isset($options['connection']) ? $options['connection'] : Database::getConnection();
-    $this->table = isset($options['table']) ? $options['table'] : 'key_value_expire';
+  public function __construct($collection, Connection $connection, $table = 'key_value_expire') {
+    parent::__construct($collection, $connection, $table);
   }
 
   /**
diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseFactory.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseFactory.php
new file mode 100644
index 0000000..65c9d68
--- /dev/null
+++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseFactory.php
@@ -0,0 +1,44 @@
+<?php
+
+/**
+ * @file
+ * Contains Drupal\Core\KeyValueStore\KeyValuesDatabaseFactory.
+ */
+
+namespace Drupal\Core\KeyValueStore;
+use Drupal\Core\Database\Connection;
+use Drupal\Core\Database\Database;
+
+/**
+ * Defines the key/value store factory for the database backend.
+ */
+class KeyValueDatabaseFactory {
+
+  /**
+   * Constructs this factory object.
+   *
+   *
+   * @param \Drupal\Core\Database\Connection $connection
+   *   The Connection object containing the key-value tables.
+   * @TODO: remove the NULL case once http://drupal.org/node/1811730 is in.
+   */
+  function __construct(Connection $connection = NULL) {
+    // @TODO: remove the ?: Database::getConnection() once
+    // http://drupal.org/node/1811730 is in.
+    $this->connection = $connection ?: Database::getConnection();
+  }
+
+  /**
+   * Constructs a new key/value database storage object for a given collection name.
+   *
+   * @param string $collection
+   *   The name of the collection holding key and value pairs.
+   * @param \Drupal\Core\Database\Connection $connection
+   *   The connection to run against.
+   * @return \Drupal\Core\KeyValueStore\DatabaseStorage
+   *   A key/value store implementation for the given $collection.
+   */
+  public function get($collection) {
+    return new DatabaseStorage($collection, $this->connection);
+  }
+}
diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php
index 7edb754..622959a 100644
--- a/core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php
+++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php
@@ -6,6 +6,7 @@
  */
 
 namespace Drupal\Core\KeyValueStore;
+use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
  * Defines the key/value store factory.
@@ -20,18 +21,42 @@ class KeyValueFactory {
   protected $stores = array();
 
   /**
+   * var \Symfony\Component\DependencyInjection\ContainerInterface
+   */
+  protected $container;
+
+
+  /**
+   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
+   */
+  function __construct(ContainerInterface $container) {
+    $this->container = $container;
+  }
+
+  /**
    * Constructs a new key/value store for a given collection name.
    *
    * @param string $collection
    *   The name of the collection holding key and value pairs.
    *
-   * @return Drupal\Core\KeyValueStore\DatabaseStorage
+   * @return \Drupal\Core\KeyValueStore\DatabaseStorage
    *   A key/value store implementation for the given $collection.
    */
   public function get($collection) {
+    global $conf;
     if (!isset($this->stores[$collection])) {
-      $this->stores[$collection] = new DatabaseStorage($collection);
+      if (isset($conf['keyvalue_collection_' . $collection])) {
+        $service_name = $conf['keyvalue_service_' . $collection];
+      }
+      elseif (isset($conf['keyvalue_default'])) {
+        $service_name = $conf['keyvalue_default'];
+      }
+      else {
+        $service_name = 'keyvalue.database';
+      }
+      $this->stores[$collection] = $this->container->get($service_name)->get($collection);
     }
     return $this->stores[$collection];
   }
 }
+
diff --git a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/GarbageCollectionTest.php b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/GarbageCollectionTest.php
index e5c1c20..6334382 100644
--- a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/GarbageCollectionTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/GarbageCollectionTest.php
@@ -7,8 +7,9 @@
 
 namespace Drupal\system\Tests\KeyValueStore;
 
-use Drupal\simpletest\UnitTestBase;
+use Drupal\Core\Database\Database;
 use Drupal\Core\KeyValueStore\DatabaseStorageExpirable;
+use Drupal\simpletest\UnitTestBase;
 
 /**
  * Tests garbage collection for DatabaseStorageExpirable.
@@ -40,7 +41,7 @@ protected function tearDown() {
    */
   public function testGarbageCollection() {
     $collection = $this->randomName();
-    $store = new DatabaseStorageExpirable($collection);
+    $store = new DatabaseStorageExpirable($collection, Database::getConnection());
 
     // Insert some items and confirm that they're set.
     for ($i = 0; $i <= 3; $i++) {
diff --git a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php
index 1e7b05c..cf95819 100644
--- a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php
+++ b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\system\Tests\KeyValueStore;
 
+use Drupal\Core\Database\Database;
 use Drupal\simpletest\UnitTestBase;
 
 /**
@@ -187,7 +188,7 @@ public function testSetIfNotExists() {
   protected function createStorage() {
     $stores = array();
     foreach ($this->collections as $i => $collection) {
-      $stores[$i] = new $this->storageClass($collection);
+      $stores[$i] = new $this->storageClass($collection, Database::getConnection());
     }
 
     return $stores;
diff --git a/core/modules/user/lib/Drupal/user/TempStoreFactory.php b/core/modules/user/lib/Drupal/user/TempStoreFactory.php
index 473d515..ddd1a75 100644
--- a/core/modules/user/lib/Drupal/user/TempStoreFactory.php
+++ b/core/modules/user/lib/Drupal/user/TempStoreFactory.php
@@ -65,7 +65,7 @@ function get($collection, $owner = NULL) {
     }
 
     // Store the data for this collection in the database.
-    $storage = new DatabaseStorageExpirable($collection, array('connection' => $this->connection));
+    $storage = new DatabaseStorageExpirable($collection, $this->connection);
     return new TempStore($storage, $this->lockBackend, $owner);
   }
 
