diff --git a/depcalc.module b/depcalc.module
index 91de53a..655f393 100644
--- a/depcalc.module
+++ b/depcalc.module
@@ -7,30 +7,22 @@
  * Calculates recursive dependencies of any entity.
  */
 
-use Drupal\Core\Cache\Cache;
 use Drupal\Core\Entity\EntityInterface;
-use Drupal\depcalc\DependencyCalculatorEvents;
-use Drupal\depcalc\Event\InvalidateDepcalcCacheEvent;
+use Drupal\Core\Hook\Attribute\LegacyHook;
+use Drupal\depcalc\Hook\EntityHooks;
 
 /**
  * Implements hook_entity_presave().
  */
+#[LegacyHook]
 function depcalc_entity_presave(EntityInterface $entity) {
-  if ($entity->uuid()) {
-    $event = new InvalidateDepcalcCacheEvent($entity);
-    /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher */
-    $event_dispatcher = \Drupal::service('event_dispatcher');
-    $event_dispatcher->dispatch($event, DependencyCalculatorEvents::INVALIDATE_DEPCALC_CACHE);
-  }
+  \Drupal::service(EntityHooks::class)->entityPresave($entity);
 }
 
 /**
  * Implements hook_entity_delete().
  */
+#[LegacyHook]
 function depcalc_entity_delete(EntityInterface $entity) {
-  if ($uuid = $entity->uuid()) {
-    $backend = \Drupal::cache('depcalc');
-    $backend->delete($uuid);
-    Cache::invalidateTags([$uuid]);
-  }
+  \Drupal::service(EntityHooks::class)->entityDelete($entity);
 }
diff --git a/src/Hook/EntityHooks.php b/src/Hook/EntityHooks.php
new file mode 100644
index 0000000..fb78b48
--- /dev/null
+++ b/src/Hook/EntityHooks.php
@@ -0,0 +1,54 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Drupal\depcalc\Hook;
+
+use Drupal\Core\Cache\CacheBackendInterface;
+use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Hook\Attribute\Hook;
+use Drupal\depcalc\DependencyCalculatorEvents;
+use Drupal\depcalc\Event\InvalidateDepcalcCacheEvent;
+use Psr\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\DependencyInjection\Attribute\Autowire;
+
+/**
+ * Entity hooks for the depcalc module.
+ */
+final class EntityHooks {
+
+  /**
+   * Constructs a new EntityHooks object.
+   */
+  public function __construct(
+    private readonly EventDispatcherInterface $eventDispatcher,
+    #[Autowire(service: 'cache.depcalc')]
+    private readonly CacheBackendInterface $depcalcCache,
+    private readonly CacheTagsInvalidatorInterface $cacheTagsInvalidator,
+  ) {}
+
+  /**
+   * Implements hook_entity_presave().
+   */
+  #[Hook(hook: 'entity_presave')]
+  public function entityPresave(EntityInterface $entity): void {
+    if ($entity->uuid()) {
+      $event = new InvalidateDepcalcCacheEvent($entity);
+      // @todo update the intended event subscriber to subscribe to the event class instead of this constant value.
+      $this->eventDispatcher->dispatch($event, DependencyCalculatorEvents::INVALIDATE_DEPCALC_CACHE);
+    }
+  }
+
+  /**
+   * Implements hook_entity_delete().
+   */
+  #[Hook(hook: 'entity_delete')]
+  public function entityDelete(EntityInterface $entity): void {
+    if ($uuid = $entity->uuid()) {
+      $this->depcalcCache->delete($uuid);
+      $this->cacheTagsInvalidator->invalidateTags([$uuid]);
+    }
+  }
+
+}
