Fwd: [grails-user] service injection in GORM event handlers, is it possible?

View: New views
3 Messages — Rating Filter:   Alert me  

Parent Message unknown Fwd: [grails-user] service injection in GORM event handlers, is it possible?

by Sergey Bondarenko :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Grails developers!

Could you please look at this issue?
It looks like service injection does not work in domain classes when onLoad closure is invoked.
I am using Grails 1.1.1.

Thanks a lot!


Sergey


2009/11/5 Sergey Bondarenko <enterit@...>
Any update?

Thanks,

Sergey

2009/11/4 Sergey Bondarenko <enterit@...>
Just checked. It works for beforeInsert and beforeUpdate, but does not work for onLoad event.
Could you please check if it works for onLoad in your app?

Thanks a lot!


Sergey


2009/11/4 Sergey Bondarenko <enterit@...>

Daniel,

Well, this service is being injected into other services and cotroller without problems.
The service is from Acegi plugin. My Grails version is 1.1.1 (maybe that makes a difference?).
I'll try to do the same with my own service.

Thanks for helping me!

Regards,
Sergey


2009/11/3 Daniel Honig <daniel.honig@...>

Something else is probably amiss.  I've been able to access services from hibernate event handlers without issue.  Do you know that your service is being injected into other classes or use cases without issue?


On Tue, Nov 3, 2009 at 2:32 PM, Sergey Bondarenko <enterit@...> wrote:
Hi folks!


I just tried to get service injection working in GORM event handlers. I wanted to implement domain-instance security checks this way.
It looks like service injection in usual methods works properly, but service is not injected in GORM events.

Does anyone else have the same problem?

The problem looks similar to http://jira.codehaus.org/browse/GRAILS-1749


Some details below.

I wanted to implement something like this:
class Department {
    def authenticateService

    static belongsTo = Customer
   
    static transients = ['authenticateService']

    def onLoad = {
        def currentUser = User.get(authenticateService.userDomain()?.id)
        def currentCustomer = Customer.get(currentUser?.customer?.id)
        if (customer != currentCustomer) {
            throw new IllegalStateException("Cannot read data of another customer")
        }
    }
}


But it looks like service is not injected, and I always receive NPE.



Any help is appreciated!


Regards,
Sergey







Re: Fwd: [grails-user] service injection in GORM event handlers, is it possible?

by Peter Ledbrook :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Could you please look at this issue?
> It looks like service injection does not work in domain classes when onLoad
> closure is invoked.
> I am using Grails 1.1.1.

Please raise an issue.

Thanks,

Peter

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Fwd: [grails-user] service injection in GORM event handlers, is it possible?

by Sergey Bondarenko :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Done.


Thanks,

Sergey

2009/11/9 Peter Ledbrook <peter@...>
> Could you please look at this issue?
> It looks like service injection does not work in domain classes when onLoad
> closure is invoked.
> I am using Grails 1.1.1.

Please raise an issue.

Thanks,

Peter

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email