How does Grails make `params` available to a Singleton controller? (Inside Grails)

If I make the Grails controller a single singlet through:

static scope = "singleton" 

... how does Grails set the params variable for my controller actions, where are the params specific to the request?

I would understand if params tags were passed to my action methods as variables, but here params are only available and available (and different for simultaneous requests, despite the fact that there is only one instance of my controller).

How is this implemented under the hood?

+4
source share
1 answer

Each request receives its own stream, so the request, response, parameters, session, etc. available regardless of whether the controller is single or created new for each request. It would be different if these variables were fields in the class, but this is not so.

Under the hood, this is implemented by the AST transformation, which is mixed in org.codehaus.groovy.grails.plugins.web.api.ControllersApi in controller classes, which adds methods like getParams() (which you can use as the params property). They call RequestContextHolder.currentRequestAttributes() to get the stream information.

+8
source

Source: https://habr.com/ru/post/1499429/


All Articles