Closed rollsappletree closed 3 years ago
As mentioned: use dependency injection instead of using the service locator ;)
E.g. https://symfony.com/doc/current/service_container/autowiring.html#an-autowiring-example
You should be able to inject a Client instance by adding the Client interface as the first argument of your indexAction.
Best regards, Charles
Hi, I've gone with injecting the Container, 'cause I need to get the client based on runtime variable (such as client).
That is not the best solution (would have been with a service locator as you said) but I think is not possible to do as is.
Cheers C
Hi, @rollsappletree I have the same problem but don't understand the solution. Could you give me an example please ? Thank you very much :)
Symfony 4.4 has deprecated
Symfony\Bundle\FrameworkBundle\Controller\Controller
, suggesting to go withSymfony\Bundle\FrameworkBundle\Controller\AbstractController
.Consider this example:
will give you "Service "csa_guzzle.client.XXXX" not found: even though it exists in the app's container, the container inside "App\Controller\RedirectController" is a smaller service locator that only knows about the "http_kernel", "parameter_bag", "request_stack", "router" and "session" services. Try using dependency injection instead."
Any way to fix this?