Service classes for non transactional logic

18 views
Skip to first unread message

clr meno

unread,
Apr 1, 2017, 2:16:15 PM4/1/17
to Grails Dev Discuss
Is it recommended to add business logic or utility methods, that don't interact with domain classes, in Service classes? Or is preferable to add it in the Src/groovy?

Jeff Brown

unread,
Apr 1, 2017, 3:49:23 PM4/1/17
to Grails Dev Discuss
Sure, there are plenty of things that you might put in a Service that
don’t have anything to do with a database.



JSB

--
Jeff Scott Brown
OCI Grails Practice Lead
Principal Software Engineer

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/

clr meno

unread,
Apr 1, 2017, 4:25:34 PM4/1/17
to Grails Dev Discuss
Thanks Jeff. If thats the case then how to decide if a non transactional class needs to go in Src or Service ?

Jeff Brown

unread,
Apr 3, 2017, 10:14:03 AM4/3/17
to Grails Dev Discuss
On 1 Apr 2017, at 15:25, clr meno wrote:

> Thanks Jeff. If thats the case then how to decide if a non
> transactional
> class needs to go in Src or Service ?
>

Understanding what the class is for and how Services behave will help
you decide. For example, if you don’t want an instance of the class
automatically added to the Spring application context as a bean, don’t
make it a service. Another example, if you are writing a class to
define Groovy Extension Methods, it would be silly to make that class a
Service.

In short, make it a Service if there is a reason to and if there
isn’t, don’t.
Reply all
Reply to author
Forward
0 new messages