{"id":4862,"date":"2011-12-29T15:28:35","date_gmt":"2011-12-29T09:58:35","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=4862"},"modified":"2011-12-29T15:31:37","modified_gmt":"2011-12-29T10:01:37","slug":"discovering-grails-goodness-scoped-services","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/discovering-grails-goodness-scoped-services\/","title":{"rendered":"Discovering grails goodness: Scoped Services"},"content":{"rendered":"<p>Recently, I got to learn about the scoped services in grails and I found it worth sharing. For instance: A Service marked as &#8216;session&#8217; 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.<br \/>\n[java]<br \/>\nclass SessionDataService {<br \/>\n     static scope = &#8216;session&#8217;<br \/>\n     Date lastLogin =new Date()<br \/>\n    String getInfo()<br \/>\n    {<br \/>\n        &quot;lastLogin: ${lastLogin.format(&#8216;HH:mm:ss&#8217;)}&quot;<br \/>\n    }<br \/>\n}<br \/>\n[\/java]<\/p>\n<p>So, wherever I intend to use session for storing user data, I would rather use session scoped service.<\/p>\n<p>Hope that helps.<\/p>\n<p>Best Regards<br \/>\nMohd Farid<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I got to learn about the scoped services in grails and I found it worth sharing. For instance: A Service marked as &#8216;session&#8217; 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. [&hellip;]<\/p>\n","protected":false},"author":26,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":6},"categories":[7],"tags":[229],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/4862"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=4862"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/4862\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=4862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=4862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=4862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}