Контроллер:
use App\Service\ExtraService;
...
$extra = new ExtraService();
Служба:
namespace App\Service;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
class ExtraService
{
private $em;
private $session;
public function __construct(EntityManagerInterface $em,SessionInterface $session){
$this->em = $em;
$this->session = $session;
...
После прочтения документации я ожидал загрузить (внедрить, автопроводить) сущности Doctrine EntityManager и Session в свойства $ em и $ session должны быть готовы к использованию внутри класса ExtraService. Вместо этого я получаю:
Слишком мало аргументов для функции App \ Service \ ExtraService :: __ construct (), 0 передано
Я проверил services.yaml, и у меня есть:
# 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,Entity,Migrations,Tests,Kernel.php}'
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
Я даже пытался явно настроить аргументы в services.yaml, как в руководстве (https://symfony.com/doc/current/service_container.html#services -explicitly-configure-wire-services ), но я не могу понять код для выполнения этой работы.