Grails: embed a service in a Command object

I have a command class that needs to call a service.

import org.codehaus.groovy.grails.commons.ApplicationHolder as AH

class FilterVisitCommand {

    def accessRightsService = AH.application.mainContext.accessRightsService
    def customerService = AH.application.mainContext.customerService
...
}

Such a vision of the service with the help of the application owner works, however, is corrupted. Is there any other way for the service to be introduced? Only the class "def accessRightsService" does not work for the command class.

+5
source share
2 answers

If you enter a service in a command object for verification, you may need to reference the service through the command object.

class FilterVisitCommand {

    def accessRightsService

    static constraints = {
        foo(validator: { foo, cmd ->
            cmd.accessRightsService.bar()
        })
    }
}
+14
source

Grails rich domain plugin includes engineering, validation, ... for regular Groovy classes.

0
source

All Articles