Kristen Joseph-Delaffon
Kristen Joseph-Delaffon

Reputation: 1291

Symfony 3.3 autoconfigure services and usage

I updated my project to Symfony 3.3. I want to use the new autoconfigure feature for services. I tried to get rid of $this->get() but I have errors in Controllers and Commands.

With the code sample below in a Controller, I have this error:

recapitulatifCollesAction() requires that you provide a value for the "$checkGele" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.

In commands, I don't know how to get rid of $container->get() at all.

Do you have an idea how I can get this to work ?

Controller:

public function recapitulatifCollesAction($estEnCours, CheckGeleService $checkGele)
{
    // ...
    $checkGele->getGeleAutorisation($colle);
    // ...
}

My config:

services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false

Edit : new error after modifying config.yml

New error message

Upvotes: 2

Views: 489

Answers (1)

yceruto
yceruto

Reputation: 9585

For controllers you need also add the service argument resolver to autowire service in "actions" methods. This's all about default autowiring in 3.3:

services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false

    AppBundle\:
        resource: '../../src/AppBundle/*'
        exclude: '../../src/AppBundle/{Controller, Entity, Repository}'

    AppBundle\Controller\:
        resource: '../../src/AppBundle/Controller'
        public: true
        tags: [ controller.service_arguments ]

Upvotes: 2

Related Questions