Csla 3.0.x - Csla.ApplicationContext.LocalContext question

Csla 3.0.x - Csla.ApplicationContext.LocalContext question

Old forum URL: forums.lhotka.net/forums/t/7050.aspx


glenntoy posted on Thursday, June 04, 2009

Hi guys,

I'v read the Csla 2.1 handbook, one of the additions is the LocalContext. In the example, it passes the connection and transaction object. I was wondering, if we could store other sorts of data (e.g. a readonlylist) that will be shared in both U.I. and B.O. code?

My scenario is when the application starts, it tries to retrieved the list of countries through a read-only list. I was thinking would it be okay to store the readonlylist in the LocalContext for storing lookup data ?

JoeFallon1 replied on Friday, June 05, 2009

LocalContext is available on the client OR on the server (but they are different).

GlobalContext is transferred between both and is the same on both.

You mention sharing with the UI so that is why you should choose the right context.

I don't see why you can't store a read only list in it.

Joe

ajj3085 replied on Friday, June 05, 2009

Well, you could use the LocalContext, but it won't travel between client and server.

But if you're caching data, I'd argue you wouldn't want to have that cached list shared automatically between both.. because that means the list goes from client to server and back with EVERY dataportal call. That will bog things down. A better approach would be to simply cache on the client, and on the server, which is what you'd do if you stored the list in the LocalContext. Both places have the cached list, and you're not transfering it back and forth each time.

glenntoy replied on Sunday, June 07, 2009

thanks for the replies. I preferred to store on one of the Context in ApplicationContext depending on my needs.

JonnyBee replied on Sunday, June 07, 2009

Hi,

Or you could use the same singelton pattern as NameValueList does. Whether you want cache the list in LocalContext or a member variable in the singelton instance is up to you.

Forms and other Business classes would the use the static getter on your ReadOnly class as usual and not be bothered whether it is cached or not. 

/jonny


RockfordLhotka replied on Sunday, June 07, 2009

The short answer is that, in a smart client scenario, you can use LocalContext as a cache, yes. It is basically a place to store any global data.

Now whether you should do that is a different matter. Using LocalContext in this manner is much like creating global variables, and any FORTRAN programmer will tell you about the evils of such a thing. Worse than GOTO statements imo.

Copyright (c) Marimer LLC