-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Service dependency injection for controller action: Getting CSP nonce in controller #345
Comments
You can use |
Thanks for your reply @martijnc. Is the "nelmio_security.csp_listener" service available to dependency injection? I don't see anything from "nelmio_security" available when searching for it with |
The Can you find it with |
I see 26 services containing "nelmio_security" via I did attempt to declare "Nelmio\SecurityBundle\EventListener\ContentSecurityPolicyListener" in my services configuration to be available for auto-wiring however the service doesn't appear to be compatible with that:
I think perhaps I've missed an approach to DI that predates auto-wiring? I went from the Symfony 2/3 days where using |
Because autowiring for the service does not work, you need to wire it manually via the service configuration. See "Explicitly Configuring Services and Arguments "on the documentation page you linked. You don't need to redefine the If your service is
|
That seemed to work. I had to also include the other arguments that I had previously given with auto-wiring, but the CSP listener now goes into my class as expected. Thanks for the workaround. Is there a particular reason why the CSP listener class would not support auto-wiring, or is it a pending improvement? |
It's just old code predating autowiring.. These days I guess there would not be service names at all and rather just use classes with autowiring, but tbh I am not 100% sure about the latest bundle best practices. Anyway could be fixed for sure, but it's work :) |
Hello,
Does this bundle expose any services for use with a controller action via dependency injection?
debug:autowiring
didn't appear to reveal any.The purpose for this is I need to provide a ReCAPTCHA bundle form instance with a nonce from this CSP provider.
The text was updated successfully, but these errors were encountered: