Showing posts with label dependency injection. Show all posts
Showing posts with label dependency injection. Show all posts

Tuesday, May 4, 2010

service dependency injection does not work in scaffolded controllers

When I wanted to access user information in the scaffolding code of the controller (/src/scaffolding/Controller.groovy) my first guess was to define the authenticateService and let dependency injection do the trick. Unfortunately, this approach did not work.

def authenticateService is never injected and therfore a useless null object.

I spent some time on google and it turned out that this is an open issue and that others had stumbled about the same problem. I was happy to see that someone had found a workaround:

def authenticateService = org.codehaus.groovy.grails.commons.ApplicationHolder.application.mainContext.getBean("authenticateService")


Using this approach arbitrary services can be injected into the scaffolded controllers.