(Quick Reference)
scope
Purpose
Changes the scope of a service
Examples
class BookService {
static scope = "session"
…
}Description
By default services are "singleton" scoped which means that clients of a service only ever use a single instance (a singleton) of the service. This behaviour can be changed by specifying a
scope attribute with on the following values:
prototype - A new service is created every time it is injected into another class
request - A new service will be created per request
flash - A new service will be created for the current and next request only
flow - In web flows the service will exist for the scope of the flow
conversation - In web flows the service will exist for the scope of the conversation. ie a root flow and its sub flows
session - A service is created for the scope of a user session
singleton (default) - Only one instance of the service ever exists
See guide:scopedServices in the user guide for more information.
scope
Propósito
Define o escopo de um service
Exemplos
class BookService {
static scope = "session"
…
}Descrição
Por padrão, os Services no Grails possuem o escopo "singleton". Isto significa que todos os clientes irão utilizar a mesma instância do service. Este comportamento pode ser alterado definindo o atributo
scope da classe para um dos seguintes valores.
prototype - Um novo service é criado toda vez em que este Service for injetado em outra classe
request - Um novo service é criado para cada request
flash - Um novo service é criado para este e para o próximo request
flow - Nos webflows, este service irá existir no escopo do flow
conversation - Nos webflows, este service irá existir no escopo da conversação, ou seja, para o flow principal e flows derivados.
session - Um service único é usado para cada sessão http
singleton (padrão) - Apenas uma instância é usada para todos os clientes
Consulte guide:scopedServices no Guia do usuário para mais detalhes.