This page last changed on Mar 27, 2006 by joncrlsn.

Services

Grails Services

A service is a class that holds one or more methods that implement business logic. Logical parts of the business logic are contained in seperate service classes. Services are demarcated by transactions to make units of work atomic on the persistence level. When certain types of exceptions are thrown transactions are rolled back.

Services need to be registered with the middle tier and also need transactional configuration next to the configuration of optional AOP services.

Services are application-scoped, which means it is not a good idea to use instance variables because they can and will be modified concurrently (at the same time).

Coding conventions for services

Service class names should start with the name of the service and end with "Service". A country service would thus be called "CountryService".

By default transaction demarcation is enabled for all services. Transaction demarcation can be disabled for specific services by creating a "transactional" property and settting is to false:

class CountryService {
    @Property boolean transactional = false
}

Other services can be injected into a service by creating corresponding properties. To inject the CountryService create a "countryService" property.

@Property CountryService countryService
Document generated by Confluence on Mar 29, 2006 08:46