question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

!tagged service not working

See original GitHub issue

I have a DataProvider with constructor like this.

public function __construct(EntityManagerInterface $manager, iterable $extension)

registered as service

  pablo.data_provider.project_data_provider:
    class: 'PabloBundle\DataProvider\ProjectDataProvider'
    arguments:
      - '@doctrine.orm.entity_manager'
      - !tagged 'api_platform.doctrine.orm.query_extension.item'
    tags:
      - { name: 'api_platform.collection_data_provider', priority: 1 }
      - { name: 'api_platform.item_data_provider', priority: 2 }

but I always get this error

Cannot autowire service “PabloBundle\DataProvider\ProjectDataProvider”: argument “$extension” of method “__construct()” is type-hinted “iterable”, you should configure its value explicitly.

I just followed the docs written here -> https://api-platform.com/docs/core/data-providers#injecting-extensions-pagination-filter-eagerloading-etc

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
flaushicommented, Jun 18, 2019

Solved it on my own, but learned a lot during this, see https://stackoverflow.com/a/56655789/5330805

Viele Grüße, Olli Demetz

Von meinem iPhone gesendet

Am 18.06.2019 um 19:06 schrieb Teoh Han Hui notifications@github.com:

@flaushi:

But my constructor is called twice!

You should open an issue on Symfony, perhaps? But I suspect you may be doing something wrong somewhere. Maybe try the #support channel on Symfony Slack.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

0reactions
MAbohassancommented, Jun 20, 2020

When you define your service like this

report_helper:
        class: App\Service\ReportHelper
        public: true
        arguments: [!tagged app.reportplaceholder]

you are creating a new service which id is report_helper, Try to debug the container

php bin/console debug:container

you will find your service but with report_helper id, so unless you tried to override your controller definition in service.yaml and pass it the correct service like this

    App\Controller\DefaultController:
        tags: [controller.service_arguments]
        bind:
            $placeholders: '@report_helper'

It won’t work as the service container wouldn’t be able to detect what do you mean by iterable, because it’s trying to using the service which he autowired automatically.

So the solution is what @flaushi says you can use alias to be like this

report_helper:
        alias: App\Service\ReportHelper
        public: true
        arguments: [!tagged app.reportplaceholder]

Or you can use alias directly by using it as service id like this

App\Service\ReportHelper:
        public: true
        arguments: [!tagged app.reportplaceholder]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Android App Troubleshooting - Knowledge Base
If you continue to experience an app problem after updating to the current version, some issues may occur due to a networking issue...
Read more >
Tagged.com - Is Tagged Down Right Now?
Tagged down? Check whether Tagged.com server is down right now or having outage problems for everyone or just for you.
Read more >
Reference Tagged Services cannot be resolved - Stack Overflow
You want to add a custom tag and inject all services in your parent service. You have a syntax error, the argument _instanceof...
Read more >
Troubleshoot issues related to tagging tasks in Amazon ECS
If you are unable to add tags to your ECS service, do the following: ... Confirm that your ECS tags are within the...
Read more >
Reference Tagged Services combined with Autoconfiguring ...
Symfony version(s) affected: 4.3.11 Description Reference Tagged Services combined with Autoconfiguring Tags does not work How to reproduce ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found