Grails Service Classes

We’re going to write a method that will create several Task instances and add them to the tasks property of a newly created TekEvent. We will define this method in a service class. A Grails service class is a Plain Old Groovy Object (POGO) located in the grails-app/services directory and with a name ending in Service. By following these conventions, this plain old Groovy object will be endowed with magical powers.

Service classes are a great way to keep extra code out of our controllers. When we have application logic that doesn’t fit well in any domain class—for example, logic that involves multiple domain classes—it is tempting to add this code to the controller. Doing this can lead to bloated controllers that are ...

Get Grails 2: A Quick-Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.