Symfony migration from 3.4 to 4.4

  symfony

I am transferring the application from Symfony 3.4 to 4.4, everything works great except for one exception, when I want to inject a service into the controller, for example, I get an error:

The controller for URI "/zamow/sprawdz-zamowienie" is not callable: Controller "TesterOfferBundleControllerOrderController" has required constructor arguments and does not exist in the container. Did you forget to define the controller as a service?

I try add to services.yaml

TesterOfferBundleController:
    resource: '../src/Tester/OfferBundle/Controller/'
    tags: ['controller.service_arguments']

But I still have this same problem.

My controller constructor:

class OrderController extends AbstractController implements PreloadController {

    /**
     * @var OfferService
     */
    private $offerService;

    public function __construct(OfferService $offerService)
    {
        $this->offerService = $offerService;
    }

My controller namespace is:

namespace TesterOfferBundleController;

Any idea?

Result for bin/console debug:container OrderController
enter image description here

My config/services.yaml

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App:
        resource: '../src/'
        exclude:
            - '../src/DependencyInjection/'
            - '../src/Entity/'
            - '../src/Kernel.php'
            - '../src/Tests/'

    # controllers are imported separately to make sure services can be injected
    # as action arguments even if you don't extend any base controller class
    AppController:
        resource: '../src/Controller/'
        tags: ['controller.service_arguments']
    TesterOfferBundleController:
        resource: '../src/Tester/OfferBundle/Controller/'
        tags: ['controller.service_arguments']

My app/config/services.yaml

# Learn more about services, parameters and containers at
# http://symfony.com/doc/current/service_container.html
parameters:
#    parameter_name: value

services:
    _defaults:
        autowire: true
        public: true
    twig.extension.stringloader:
#        class: Twig_Extension_StringLoader
        class: TwigExtensionStringLoaderExtension
        tags:
            - { name: twig.extension }
    logger:
        alias: 'monolog.logger'
        public: true
#    service_name:
#        class: AppBundleDirectoryClassName
#        arguments: ["@another_service_name", "plain_value", "%parameter_name%"]

Source: Symfony Questions

LEAVE A COMMENT