diff --git a/src/Plugin/RulesAction/BanIP.php b/src/Plugin/RulesAction/BanIP.php
index bf54cc4..57f9ff4 100644
--- a/src/Plugin/RulesAction/BanIP.php
+++ b/src/Plugin/RulesAction/BanIP.php
@@ -5,7 +5,7 @@ namespace Drupal\rules\Plugin\RulesAction;
 use Drupal\ban\BanIpManagerInterface;
 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
 use Drupal\rules\Core\RulesActionBase;
-use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\RequestStack;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
@@ -41,11 +41,11 @@ class BanIP extends RulesActionBase implements ContainerFactoryPluginInterface {
   protected $banManager;
 
   /**
-   * The corresponding request.
+   * The corresponding request stack.
    *
-   * @var \Symfony\Component\HttpFoundation\Request
+   * @var \Symfony\Component\HttpFoundation\RequestStack
    */
-  protected $request;
+  protected $requestStack;
 
   /**
    * {@inheritdoc}
@@ -56,7 +56,7 @@ class BanIP extends RulesActionBase implements ContainerFactoryPluginInterface {
       $plugin_id,
       $plugin_definition,
       $container->get('ban.ip_manager'),
-      $container->get('request')
+      $container->get('request_stack')
     );
   }
 
@@ -71,13 +71,13 @@ class BanIP extends RulesActionBase implements ContainerFactoryPluginInterface {
    *   The plugin implementation definition.
    * @param \Drupal\ban\BanIpManagerInterface $ban_manager
    *   The ban manager.
-   * @param \Symfony\Component\HttpFoundation\Request $request
-   *   The corresponding request.
+   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
+   *   The corresponding request stack.
    */
-  public function __construct(array $configuration, $plugin_id, $plugin_definition, BanIpManagerInterface $ban_manager, Request $request) {
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, BanIpManagerInterface $ban_manager, RequestStack $request_stack) {
     parent::__construct($configuration, $plugin_id, $plugin_definition);
     $this->banManager = $ban_manager;
-    $this->request = $request;
+    $this->requestStack = $request_stack;
   }
 
   /**
@@ -88,7 +88,7 @@ class BanIP extends RulesActionBase implements ContainerFactoryPluginInterface {
    */
   protected function doExecute($ip = NULL) {
     if (!isset($ip)) {
-      $ip = $this->request->getClientIp();
+      $ip = $this->requestStack->getCurrentRequest()->getClientIp();
     }
 
     $this->banManager->banIp($ip);
diff --git a/tests/src/Unit/Integration/Action/BanIPTest.php b/tests/src/Unit/Integration/Action/BanIPTest.php
index 4a7dd68..cd2098e 100644
--- a/tests/src/Unit/Integration/Action/BanIPTest.php
+++ b/tests/src/Unit/Integration/Action/BanIPTest.php
@@ -5,6 +5,7 @@ namespace Drupal\Tests\rules\Unit\Integration\Action;
 use Drupal\ban\BanIpManagerInterface;
 use Drupal\Tests\rules\Unit\Integration\RulesIntegrationTestBase;
 use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\RequestStack;
 
 /**
  * @coversDefaultClass \Drupal\rules\Plugin\RulesAction\BanIP
@@ -30,6 +31,11 @@ class BanIPTest extends RulesIntegrationTestBase {
   protected $request;
 
   /**
+   * @var \Symfony\Component\HttpFoundation\RequestStack|\Prophecy\Prophecy\ProphecyInterface
+   */
+  protected $requestStack;
+
+  /**
    * {@inheritdoc}
    */
   public function setUp() {
@@ -39,8 +45,14 @@ class BanIPTest extends RulesIntegrationTestBase {
     $this->banManager = $this->prophesize(BanIpManagerInterface::class);
     $this->container->set('ban.ip_manager', $this->banManager->reveal());
 
+    // Mock a request.
     $this->request = $this->prophesize(Request::class);
-    $this->container->set('request', $this->request->reveal());
+
+    // Mock the request_stack service, make it return our mocked request,
+    // and register it in the container.
+    $this->requestStack = $this->prophesize(RequestStack::class);
+    $this->requestStack->getCurrentRequest()->willReturn($this->request->reveal());
+    $this->container->set('request_stack', $this->requestStack->reveal());
 
     $this->action = $this->actionManager->createInstance('rules_ban_ip');
   }
@@ -116,7 +128,6 @@ class BanIPTest extends RulesIntegrationTestBase {
     $this->banManager->banIp($ip)->shouldBeCalledTimes(1);
 
     $this->action->execute();
-
   }
 
 }
