Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails: Inject Service into the Command Object

I have a command class which 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
...
}

This kind service definition via application holder is working however is depracated. Is there another way to let the service be injected? Only "def accessRightsService" does not work for the command class.

like image 641
John Avatar asked Apr 17 '12 12:04

John


1 Answers

If you are injecting a service into a command object for validation, you may need to reference the service via the command object.

class FilterVisitCommand {

    def accessRightsService

    static constraints = {
        foo(validator: { foo, cmd ->
            cmd.accessRightsService.bar()
        })
    }
}
like image 170
doelleri Avatar answered Oct 09 '22 13:10

doelleri