I am trying to build a service that will leverage the Pathauto service so my class looks like this.

namespace Drupal\some_system;

use Drupal\pathauto\PathautoGenerator;
use Drupal\pathauto\AliasCleaner;
use Symfony\Component\DependencyInjection\ContainerInterface;

class ProcessUrl
   * @var PathautoGenerator

  protected $pathautoGenerator;

   * @var AliasCleaner
  protected $aliasCleaner;

   * ProcessUrl constructor.
   * @param PathautoGenerator $pathautoGenerator
   * @param AliasCleaner $aliasCleaner

  public function __construct(PathautoGenerator $pathautoGenerator, AliasCleaner $aliasCleaner)
    $this->pathautoGenerator = $pathautoGenerator;
    $this->aliasCleaner = $aliasCleaner;

   * {@inheritdoc}
  public static function create(ContainerInterface $container) {
    return new static(

  public function testurl(){
    dump("Need to reach Here");


and my services.yml file looks like this.

    class: Drupal\some_system\ProcessUrl
    argumrnts: ['@pathauto.generator','@pathauto.alias_cleaner']

Now when I call this service \Drupal::service('some_group_system.process_url')->testurl(); it throws an error to me saying

Too few arguments to function Drupal\some_system\ProcessUrl::__construct(), 0 passed in /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 265 and exactly 2 expected

I cleared cache and reran but not sure why it is saying this. Please help on this.


You have a typo in your services.yml file, you misspelled arguments.

Additionally, for a service, you don't need to (and shouldn't) define the create method. Your dependent services are injected from services.yml, but keep your constructor as is.

The only time you need to define the create method to inject dependencies is when working with plugins, controllers, forms, etc as mentioned in the dependency injection documentation on d.o.


Sorry it was a spelling mistake

 argumrnts: ['@pathauto.generator','@pathauto.alias_cleaner']

should be

arguments: ['@pathauto.generator','@pathauto.alias_cleaner']

Do not need even create method but got confused.

Not the answer you're looking for? Browse other questions tagged or ask your own question.