diff --git a/cache_example/src/Forms/CacheExampleForm.php b/cache_example/src/Forms/CacheExampleForm.php
index 11c5f4c..2995242 100644
--- a/cache_example/src/Forms/CacheExampleForm.php
+++ b/cache_example/src/Forms/CacheExampleForm.php
@@ -11,12 +11,68 @@ use Drupal\Core\Form\FormBase;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Cache\Cache;
 use Drupal\Core\Cache\CacheBackendInterface;
+use Symfony\Component\HttpFoundation\Request;
+use Drupal\Core\Session\AccountProxyInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
 
 
 /**
  * Form with examples on how to use cache.
  */
 class CacheExampleForm extends FormBase {
+  /**
+   * The current request.
+   *
+   * @var \Symfony\Component\HttpFoundation\Request
+   */
+  protected $request;
+
+  /**
+   * The current user.
+   *
+   * @var \Drupal\Core\Session\AccountProxyInterface
+   */
+  protected $currentUser;
+
+  /**
+   * The cache.default cache backend.
+   *
+   * @var \Drupal\Core\Cache\CacheBackendInterface
+   */
+  protected $cacheBackend;
+
+  /**
+   * Dependency injection trough the constructor.
+   *
+   * @param \Symfony\Component\HttpFoundation\Request $request
+   *   The currently active request object.
+   * @param \Drupal\Core\Session\AccountProxyInterface $current_user
+   *   The current active user.
+   * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
+   *   The cache object associated with the default bin.
+   */
+  public function __construct(Request $request, AccountProxyInterface $current_user, CacheBackendInterface $cache_backend) {
+    $this->request = $request;
+    $this->currentUser = $current_user;
+    $this->cacheBackend = $cache_backend;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container) {
+    // Forms that require a Drupal service or a custom service should access
+    // the service using dependency injection.
+    // @link https://www.drupal.org/node/2203931.
+    // Those services are passed in the $container trough the static create
+    // method.
+    $request = $container->get('request_stack')->getCurrentRequest();
+    $current_user = $container->get('current_user');
+    $cache_backend = $container->get('cache.default');
+
+    // Instantiates this form class.
+    return new static($request, $current_user, $cache_backend);
+  }
 
   /**
    * {@inheritdoc}
@@ -39,7 +95,7 @@ class CacheExampleForm extends FormBase {
     //   the object is to be saved.
     //
     // cache_get() returns the cached object or FALSE if object does not exist.
-    if ($cache = \Drupal::cache()->get('cache_example_files_count')) {
+    if ($cache = $this->cacheBackend->get('cache_example_files_count')) {
       /*
        * Get cached data. Complex data types will be unserialized automatically.
        */
@@ -55,7 +111,7 @@ class CacheExampleForm extends FormBase {
       // being saved into cache.
       // Here we use the default setting and create an unexpiring cache item.
       // See below for an example that creates an expiring cache item.
-      \Drupal::cache()->set('cache_example_files_count', $files_count, CacheBackendInterface::CACHE_PERMANENT);
+      $this->cacheBackend->set('cache_example_files_count', $files_count, CacheBackendInterface::CACHE_PERMANENT);
     }
 
     $end_time = microtime(TRUE);
@@ -65,7 +121,12 @@ class CacheExampleForm extends FormBase {
     $intro_message = '<p>' . t('This example will search the entire drupal folder and display a count of the files in it.') . ' ';
     $intro_message .= t('This can take a while, since there are a lot of files to be searched.') . ' ';
     $intro_message .= t('We will search filesystem just once and save output to the cache. We will use cached data for later requests.') . '</p>';
-    $intro_message .= '<p>' . t('<a href="@url">Reload this page</a> to see cache in action.', array('@url' => \Drupal::request()->getRequestUri())) . ' ';
+    $intro_message .= '<p>'
+      . t(
+        '<a href="@url">Reload this page</a> to see cache in action.',
+        array('@url' => $this->request->getRequestUri())
+      )
+      . ' ';
     $intro_message .= t('You can use the button below to remove cached data.') . '</p>';
 
     $form['file_search'] = array(
@@ -104,7 +165,7 @@ class CacheExampleForm extends FormBase {
       '#markup' => t('A cache item can be set as CACHE_PERMANENT, meaning that it will only be removed when explicitly cleared, or it can have an expiration time (a Unix timestamp).'),
     );
 
-    $item = \Drupal::cache()->get('cache_example_expiring_item', TRUE);
+    $item = $this->cacheBackend->get('cache_example_expiring_item', TRUE);
     if ($item == FALSE) {
       $item_status = t('Cache item does not exist');
     }
@@ -157,7 +218,7 @@ class CacheExampleForm extends FormBase {
       '#type' => 'submit',
       '#value' => t('Clear or expire cache'),
       '#submit' => array(array($this, 'cacheClearing')),
-      '#access' => \Drupal::currentUser()->hasPermission('administer site configuration'),
+      '#access' => $this->currentUser->hasPermission('administer site configuration'),
     );
 
     return $form;
@@ -175,7 +236,7 @@ class CacheExampleForm extends FormBase {
     // expiration time. The second argument (required here) is the cache bin.
     // Using cache_clear_all() explicitly in this way
     // forces removal of the cached item.
-    \Drupal::cache()->delete('cache_example_files_count');
+    $this->cacheBackend->delete('cache_example_files_count');
 
     // Display message to the user.
     drupal_set_message(t('Cached data key "cache_example_files_count" was cleared.'), 'status');
@@ -202,7 +263,7 @@ class CacheExampleForm extends FormBase {
     // Set the expiration to the actual Unix timestamp of the end of the
     // required interval. Also add a tag to it to be able to clear caches more
     // precise.
-    \Drupal::cache()->set('cache_example_expiring_item', $expiration_friendly, $expiration, $tags);
+    $this->cacheBackend->set('cache_example_expiring_item', $expiration_friendly, $expiration, $tags);
     drupal_set_message(t('cache_example_expiring_item was set to expire at %time', array('%time' => $expiration_friendly)));
   }
 
@@ -214,14 +275,14 @@ class CacheExampleForm extends FormBase {
       case 'expire':
         // Here we'll remove all cache keys in the 'cache' bin that have
         // expired.
-        \Drupal::cache()->garbageCollection();
+        $this->cacheBackend->garbageCollection();
         drupal_set_message(t('\Drupal::cache()->garbageCollection() was called, removing any expired cache items.'));
         break;
 
       case 'remove_all':
         // This removes all keys in a bin using a super-wildcard. This
         // has nothing to do with expiration. It's just brute-force removal.
-        \Drupal::cache()->deleteAll();
+        $this->cacheBackend->deleteAll();
         drupal_set_message(t('ALL entries in the "cache" bin were removed with \Drupal::cache()->deleteAll().'));
         break;
 
