1

I try configure my services in Symfony 5.5 with tags and a resource folder and I also used some different notations. Either I got an empty iterator as constructor param or the exception "Cannot autowire service ... argument "..." of method "__construct()" is type-hinted "iterable", you should configure its value explicitly.".

I used that easy feature in previous versions and I followed that instruction: https://symfony.com/doc/current/service_container/tags.html#reference-tagged-services.

Here that related part of my services.yaml:

services:
    _defaults:
        autowire: true
        autoconfigure: true

    App\Service\LinkTypeGuesser\:
        resource: '../src/Service/LinkTypeGuesser'
        tags: ['link.type.guesser']

    App\Service\LinkTypeGuesser:
        arguments:
            - !tagged_iterator link.type.guesser

My "parent" service class constructor looks like that:

class LinkTypeGuesser
{
    private $guessers;

    public function __construct(iterable $linkTypeGuessers)
    {
        $this->guessers = $linkTypeGuessers;
    }
}

Any hints what I missed in my configuration?

2
  • Hi, but you have duplicated App\Service\LinkTypeGuesser Mar 26, 2020 at 22:16
  • @EugeneRuban No. The first part is a directory with the tagged subservices and the second is a class, the service itselfs. But I tried renaming the folder and the namespace to exclude a name conflict issue. This was not the reason and the same error remains.
    – Daniel
    Mar 27, 2020 at 11:30

1 Answer 1

1

I don't really know your repository therefor the file system.
First of all the argument resource is not supported.
Supported arguments are "shared", "lazy", "public", "properties", "configurator", "calls", "tags", "autowire", "bind"

resource: '../src/Service/LinkTypeGuesser'

Symfony will find your resources based on the Fully Qualified Namespace, you have set as an key. This means everything that implements or extends this Service will be tagged.

  1. You want to add a custom tag and inject all services in your parent service. You have a syntax error, the argument _instanceof is missing.

GO ahead and try this code (Please change whitespaces to match yaml format):

services:
    _defaults:
        autowire: true
        autoconfigure: true
    _instanceof:
      App\Service\LinkTypeGuesser:
        tags: ['link.type.guesser']

    App\Service\LinkTypeGuesser:
        arguments:
            - !tagged_iterator link.type.guesser

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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