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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access