Rafał Świerczek
Rafał Świerczek

Reputation: 135

Symfony 4.3 - Cannot autowire service argument that references class "Symfony\Component\Security\Core\Security"

I'm using Symfony 4.3.

I have a problem with autowiring service argument in controller method. It seems like Security class cannot be found.

I installed Security component by composer require symfony/security

This is row from "composer show":

symfony/security v4.3.4 Symfony Security Component

Composer.json:

"symfony/security": "4.3.*",

Services.yaml:

parameters:

services:
    _defaults:
        autowire: true
        autoconfigure: true

    App\:
        resource: '../src/*'
        exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'

    App\Controller\:
        resource: '../src/Controller'
        tags: ['controller.service_arguments']

HomeController.php:

use App\Service\DB\DBALProvider;

class HomeController extends AbstractController
{
    /**
     * @Route("/", name="index")
     */
    public function index(DBALProvider $DBALProvider)
    {

DBALProvider.php:

use Symfony\Component\Security\Core\Security;
use Doctrine\ORM\EntityManagerInterface;

class DBALProvider
{
    private $entityManager;
    private $context;
    private $user;

    public function __construct(EntityManagerInterface $entityManager, Security $security)
    {

Error that displays when I enter "/" route

Cannot resolve argument $DBALProvider of "App\Controller\HomeController::index()": Cannot autowire service "App\Service\DB\DBALProvider": argument "$security" of method "__construct()" references class "Symfony\Component\Security\Core\Security" but no such service exists.

Thanks for any suggestions.

Upvotes: 3

Views: 2501

Answers (1)

Rafał Świerczek
Rafał Świerczek

Reputation: 135

composer require symfony/security-bundle

is the solution (thanks to Cerad).

https://symfony.com/doc/current/security.html

Well I though that composer require symfony/security install all necessary bundles.

Upvotes: 3

Related Questions