Create a class in the Drupal\modulename\Hook namespace (or subdirectory). This will be automatically registered as an autowired service. Use the new Drupal\Core\Hook\Attribute\Hook attribute either on methods or on the class. If it is on the class and the class doesn't have an __invoke method then a method argument is required. The method implementing the hook has the same