I have several services: DieselCaseService, CarloanCaseService LvCaseService.
The controller decides which of services to get.
$type = $quickCheck["type"];/** * @var $caseService \App\Service\Cases\CaseInterface*/$type = 'diesel; // for test purposes$caseService = $this->get('case_service.' . $type);
The service aliases are declared like this:
case_service.diesel: alias: App\Service\Cases\DieselCaseService public: true
class DieselCaseService implements CaseInterface {...}
If I try to get the DieselCaseService, I get an error
Service "case_service.diesel" not found: even though it exists in the
app's container, the container inside
"App\Controller\Api\AccountController" is a smaller service locator that only knows about the "doctrine", "form.factory",
"fos_rest.view_handler", "http_kernel", "parameter_bag",
"request_stack", "router", "security.authorization_checker",
"security.csrf.token_manager", "security.token_storage", "serializer",
"session", "templating" and "twig" services. Try using dependency
injection instead.
What can I do? I don't want to inject all of the services to the controller