StateValue<T> with SessionStateKey attribute or IHttpContextLocatorService for Session

Topics: Web Client Software Factory, Project Management Forum, UIP Application Block discussion, User Forum
May 19, 2008 at 6:30 PM
Hi !!

I am using WCSF and looking at various code samples. I am not sure should I use 
1)  StateValue<T> with SessionStateKey attribute to access session variable across presenter OR
2) Use IHttpContextLocatorService and then use Context.Current.Session[key] to access the session?

What is the difference between the 2? When they are use or not be used? Are they 2 related with each other or they are to be used in completely different situation?

Please help.

May 21, 2008 at 2:49 PM
Edited May 21, 2008 at 2:50 PM


The specific scenario for using the StateValue class is when you require your application to store information in the session state and to share data across requests. For more information see the How to: Use Session State with Unit Testing topic.

The HttpContextLocatorService service encapsulates the access to System.Web.HttpContext.Current. Its functionality is more general and allows you to get access to all the HttpContext Members.

The main difference between them is the scope. When you only need to use the session state you may use the StateValue class and for the rest of HttpContext members (Request, Cache, Response, etc) use the HttpContextLocatorService.

FYI: The StateValue class uses the HttpContextLocatorService inside.

Please, let me know if it helps.

Mariano Conveti

May 21, 2008 at 4:08 PM

So now if I have "Order" Business Module with OrderController and "Customer" Business module with CustomerController, and I want to share some information between these 2 modules, what is the best way?

Use StateValue<T> for each information I want to share OR in each controller or use IHttpContextLocatorService and use Session out from that?

As far as the testing goes, will not be easier to use IHttpContextLocatorService in this case?