diff --git a/registration_role.info.yml b/registration_role.info.yml
index e58f397..2705c8e 100644
--- a/registration_role.info.yml
+++ b/registration_role.info.yml
@@ -2,5 +2,5 @@ name: Registration Role
 type: module
 description: 'Automatically assign a role to all new users who register.'
 package: Registration
-core_version_requirement: ^8 || ^9 || ^10 || ^11
+core_version_requirement: ^10.1 || ^11 || ^12
 configure: registration_role.setting.form
diff --git a/registration_role.install b/registration_role.install
index 8516e61..8755bcf 100644
--- a/registration_role.install
+++ b/registration_role.install
@@ -1,5 +1,7 @@
 <?php
 
+use Drupal\Component\Utility\DeprecationHelper;
+use Drupal\Core\Url;
 use Drupal\user\Entity\Role;
 
 /**
@@ -16,7 +18,7 @@ function registration_role_update_8007(&$sandbox) {
   foreach ($roles as $role) {
     if ($role->hasPermission('administer users')) {
       $roleId = $role->id();
-      user_role_grant_permissions($roleId, ['administer registration roles']);
+      DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '11.5.0', fn() => Role::loadOverrideFree($roleId)?->grantPermissions(['administer registration roles'])?->save(), fn() => user_role_grant_permissions($roleId, ['administer registration roles']));
     }
   }
 }
@@ -45,7 +47,7 @@ function registration_role_update_10001() {
   if ($role_to_select != $updated_roles) {
     $config->set('role_to_select', $updated_roles);
     $config->save();
-    $settings_form = \Drupal\Core\Url::fromRoute('registration_role.setting.form')->toString();
+    $settings_form = Url::fromRoute('registration_role.setting.form')->toString();
     \Drupal::logger('registration_role')->alert("Review user accounts registered between 2023 July 11 and now for having additional roles you did not intend for them to have.  Your site missed or reverted an update to configuration in the version 2.0.0 release of Registration Role (in a 2020 August 17 commit, in case you have been using the development branch of this module) that removed non-selected roles. Without this configuration update, up until you re-saved <a href=':url'>the settings form</a> or until now, whichever came first, users who registered after the 2.0.0 update received <em>all</em> roles.", [':url' => $settings_form]);
     \Drupal::messenger()->addWarning(t("Review user accounts registered between 2023 July 11 and now for having additional roles you did not intend for them to have.  Your site missed or reverted an update to configuration in the version 2.0.0 release of Registration Role (in a 2020 August 17 commit, in case you have been using the development branch of this module) that removed non-selected roles. Without this configuration update, up until you re-saved <a href=':url'>the settings form</a> or until now, whichever came first, users who registered after the 2.0.0 update received <em>all</em> roles.", [':url' => $settings_form]));
   }
diff --git a/registration_role.module b/registration_role.module
index e3d96b8..6adfb7a 100644
--- a/registration_role.module
+++ b/registration_role.module
@@ -4,55 +4,25 @@
  * @file
  * Module file for Registration role.
  */
-
+use Drupal\Core\Hook\Attribute\LegacyHook;
+use Drupal\registration_role\Hook\RegistrationRoleHooks;
 use \Drupal\Core\Routing\RouteMatchInterface;
 use \Drupal\user\UserInterface;
 
 /**
  * Implements hook_help().
  */
-function registration_role_help($route_name, RouteMatchInterface $route_match) {
-  $output = '';
-  switch ($route_name) {
-    case 'help.page.registration_role':
-      $output = t("Auto-assign a role upon registration.");
-      return $output;
-  }
+#[LegacyHook]
+function registration_role_help($route_name, RouteMatchInterface $route_match)
+{
+    return \Drupal::service(RegistrationRoleHooks::class)->help($route_name, $route_match);
 }
 
 /**
  * Implements hook_ENTITY_TYPE_presave() for user entities.
  */
-function registration_role_user_presave(UserInterface $user) {
-  $config = \Drupal::config('registration_role.setting');
-  $case = $config->get('registration_mode');
-
-  // Do not assign the roles by default.
-  $assign_roles = FALSE;
-
-  // Get the current user id.
-  $current_user_id = \Drupal::currentUser()->id();
-  if ($current_user_id == 0 && PHP_SAPI !== 'cli') {
-    // If the current user id is 0, then this user is self registrating, so ask
-    // the module to assign roles, if applicable.
-    $assign_roles = TRUE;
-  }
-  elseif (($current_user_id != 0 || PHP_SAPI === 'cli') && $case == 'admin') {
-    // If the current user id is not 0, then another user (admin, or anyone with
-    // the right permission) is creating this user, so the module will be asked
-    // to assign roles only if the setting is set to 'admin'.
-    $assign_roles = TRUE;
-  }
-
-  if ($user->isNew() && $assign_roles) {
-    $config = \Drupal::config('registration_role.setting');
-
-    foreach ($config->get('role_to_select') as $key => $value) {
-      // This check for value protects against old-style configuration, in case
-      // update hook registration_role_update_8008 did not run or got reverted.
-      if ($value) {
-        $user->addRole($key);
-      }
-    }
-  }
+#[LegacyHook]
+function registration_role_user_presave(UserInterface $user)
+{
+    \Drupal::service(RegistrationRoleHooks::class)->userPresave($user);
 }
diff --git a/registration_role.services.yml b/registration_role.services.yml
new file mode 100644
index 0000000..c38b2d5
--- /dev/null
+++ b/registration_role.services.yml
@@ -0,0 +1,5 @@
+
+services:
+  Drupal\registration_role\Hook\RegistrationRoleHooks:
+    class: Drupal\registration_role\Hook\RegistrationRoleHooks
+    autowire: true
diff --git a/src/Hook/RegistrationRoleHooks.php b/src/Hook/RegistrationRoleHooks.php
new file mode 100644
index 0000000..4537d17
--- /dev/null
+++ b/src/Hook/RegistrationRoleHooks.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace Drupal\registration_role\Hook;
+
+use Drupal\Core\Routing\RouteMatchInterface;
+use Drupal\user\UserInterface;
+use Drupal\Core\Hook\Attribute\Hook;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
+/**
+ * Hook implementations for registration_role.
+ */
+class RegistrationRoleHooks
+{
+    use StringTranslationTrait;
+    /**
+     * Implements hook_help().
+     */
+    #[Hook('help')]
+    public function help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match)
+    {
+        $output = '';
+        switch ($route_name) {
+            case 'help.page.registration_role':
+                $output = $this->t("Auto-assign a role upon registration.");
+                return $output;
+        }
+    }
+    /**
+     * Implements hook_ENTITY_TYPE_presave() for user entities.
+     */
+    #[Hook('user_presave')]
+    public function userPresave(\Drupal\user\UserInterface $user)
+    {
+        $config = \Drupal::config('registration_role.setting');
+        $case = $config->get('registration_mode');
+        // Do not assign the roles by default.
+        $assign_roles = FALSE;
+        // Get the current user id.
+        $current_user_id = \Drupal::currentUser()->id();
+        if ($current_user_id == 0 && PHP_SAPI !== 'cli') {
+            // If the current user id is 0, then this user is self registrating, so ask
+            // the module to assign roles, if applicable.
+            $assign_roles = TRUE;
+        } elseif (($current_user_id != 0 || PHP_SAPI === 'cli') && $case == 'admin') {
+            // If the current user id is not 0, then another user (admin, or anyone with
+            // the right permission) is creating this user, so the module will be asked
+            // to assign roles only if the setting is set to 'admin'.
+            $assign_roles = TRUE;
+        }
+        if ($user->isNew() && $assign_roles) {
+            $config = \Drupal::config('registration_role.setting');
+            foreach ($config->get('role_to_select') as $key => $value) {
+                // This check for value protects against old-style configuration, in case
+                // update hook registration_role_update_8008 did not run or got reverted.
+                if ($value) {
+                    $user->addRole($key);
+                }
+            }
+        }
+    }
+}
