Skip to content

Injecting HttpContext inside a service doesn't work #4371

Answered by thetutlage
kilobyte2007 asked this question in Help
Discussion options

You must be logged in to vote

Yes this does not work as expected. Because you are using the app.container instance which is a global instance of the container and does not have any idea about the ongoing HTTP request.

Creating model hooks that relies on HTTP request is not really a good practice, since your models will be unusable outside of an HTTP request, like model factories or commands and even REPL.

Just inject service within the controller and execute its methods before calling the create method on the model.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by RomainLanz
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants