Grails dependency inject domain classes

Posted by Don on Stack Overflow See other posts from Stack Overflow or by Don
Published on 2010-05-11T11:39:10Z Indexed on 2010/05/11 11:44 UTC
Read the original article Hit count: 251

Hi,

The Grails manual shows this example of dependency injecting domain classes:

class Book {    

    def bookService

    def buyBook() {
        bookService.buyBook(this)
    }
}

However, I tried this out, and bookService is null. My guess is that the dependency injection happens when an object is loaded from the DB, so the following will always return null

new Book().bookService

Can someone confirm this?

© Stack Overflow or respective owner

Related posts about grails

Related posts about dependency-injection