Old forum URL:

mab posted on Monday, August 01, 2011


We would like to use an dictionary entry in ApplicationContext.GlobalContext to store a value that indicates a user account has been locked out (prior to logging on). In the Fetch method of the DataAccess class, we set the value with

Csla.ApplicationContext.GlobalContext.Add("IsLockedOut", true);

However, GlobalContext (along with ApplicationContext) is cleared out during the Fetch method of SilverlightRequestProcessor, making the value unavailable by the time the code-behind of the control is reached. I am trying to access the entry with


Is there some other way to access the value in the code-behind?

RockfordLhotka replied on Tuesday, August 02, 2011

Because Silverlight requires that server interactions be async, the data portal is async. Because the data portal is async, there could be numerous simultaneous data portal calls. Because those calls will complete in unpredictable order, and because each one of them will bring back GlobalContext from that particular server call, it isn't possible for the returning GlobalContext (or any context) to automatically replace the context already on the client.

Just think of the mess that would cause!

So what we do is return GlobalContext as a property of the DataPortal object instance. You have (or can have) access to this in your factory method, and you can choose to merge the resulting GlobalContext value(s) back into the client-side GlobalContext when the callback occurs.

Something like this:

      public static void GetRoles(EventHandler<DataPortalResult<RoleEditList>> callback)
        var dp = new DataPortal<RoleEditList>();
        dp.FetchCompleted += (o, e) =>
            // use dp.GlobalContext here
            callback(o, e);

mab replied on Tuesday, August 02, 2011

Thank you very much for the explanation!

Copyright (c) Marimer LLC