Validator callbacks into Web App??

Posts   
 
    
Posts: 48
Joined: 14-Oct-2008
# Posted on: 09-Jan-2009 01:44:33   

I want to be able to update my entities with the UserId of the person editing them via my web application. I have this information available in the Session, but it seems that I have no way to get this information to the code. What I DON'T want to do is set the value in each of the 500 places I call Save() on my entities.

I have implemented a Validator w/ Dependency Injection and it works great. I thought that I would be able to do it there, but something wierd is happening... In my Validator class, I have:

public delegate HttpSessionState GetWebSession_Delegate(); public static GetWebSession_Delegate GetWebSessionState = null;

and then in my Application_Start, I set the GetWebSessionState delegate function. But when the Validator is executing, it is null.

Any suggestions?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 09-Jan-2009 04:38:03   

Could you plese post the code snippet where you set the delegate. Also the Validator's method where you are accessing it.

David Elizondo | LLBLGen Support Team
Posts: 48
Joined: 14-Oct-2008
# Posted on: 09-Jan-2009 05:05:12   

daelmo wrote:

Could you plese post the code snippet where you set the delegate. Also the Validator's method where you are accessing it.

The definition:

public class GeneralValidator : ValidatorBase
{
    public delegate HttpSessionState GetWebSession_Delegate();
    public static GetWebSession_Delegate GetWebSessionState = null;

Setting the delegate: (in my Web Global Application_Start)

GeneralValidator.GetWebSessionState = new GeneralValidator.GetWebSession_Delegate(this.GetSessionState);

Using it: (from inside my Validator)

if (GetWebSessionState != null)
{
    HttpSessionState Session = GetWebSessionState();
    q.CortexLastEditId = (int)Session["UserID"];
}

-mdb

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 09-Jan-2009 11:00:31   

and then in my Application_Start, I set the GetWebSessionState delegate function

Shouldn't this be set in Session Start?

Posts: 48
Joined: 14-Oct-2008
# Posted on: 09-Jan-2009 23:28:24   

Walaa wrote:

and then in my Application_Start, I set the GetWebSessionState delegate function

Shouldn't this be set in Session Start?

No... all I'm doing is setting up a static delegate. I only want to do this once when the app starts, not for every different session.

-mdb

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 12-Jan-2009 11:30:22   

I don't think your approach will work.

Who said that GetSessionState would fire (if it's an event), when a Validator is created and injected for an entity that's has just been created?

I think you should try to access the current session in the Validator using: System.Web.HttpContext.Current.Session, don't forget to reference System.Web.dll