(Quick Reference)

scope

Purpose

Changes the scope of a controller

Examples

class BookController {

static scope = "session"

// … }

Description

By default controllers are "prototype" scoped which means that a new controller will be created for each request. This behaviour can be changed by specifying a scope attribute with on the following values:

  • prototype (default) - A new controller will be created for each request (recommended for actions as Closure properties)
  • session - One controller is created for the scope of a user session
  • singleton - Only one instance of the controller ever exists (recommended for actions as methods)

See Controllers and Scopes in the user guide for more information.