Recently, I got to learn about the scoped services in grails and I found it worth sharing. For instance: A Service marked as ’session’ scoped would be instantiated once for a session and remains there throughout the lifetime of the session. This can be used to store user specific data in this service bean class.
class SessionDataService {
static scope = 'session'
Date lastLogin =new Date()
String getInfo()
{
"lastLogin: ${lastLogin.format('HH:mm:ss')}"
}
}
So, wherever I intend to use session for storing user data, I would rather use session scoped service.
Hope that helps.
Best Regards
Mohd Farid
