api-platform / docs

API Platform documentation
https://api-platform.com/docs/
164 stars 1.05k forks source link

Autowire attribute #1925

Open PaulCombal opened 4 months ago

PaulCombal commented 4 months ago

I didn't do too much digging, but this did't work in Symfony 7:

    public function __construct(
        #[Autowire('api_platform.doctrine.orm.state.item_provider')]
        private ProviderInterface $itemProvider,
    )

what worked:

    public function __construct(
        #[Autowire(service: CollectionProvider::class)] private readonly CollectionProvider $collectionProvider
    )

Documentation page: https://api-platform.com/docs/core/state-providers/

I had the following error with the docs code: "MyProvider::__construct(): Argument #1 ($collectionProvider) must be of type ApiPlatform\\State\\ProviderInterface, string given, called in .."