tags:

views:

13

answers:

1

Hello to all. I have a IQueryable function. In that function, I need to store and retrieve data to Session; can you guys point me in the right direction.

I've looked at the HttpSessionStatBase where the session is usually taken from HttpContext.Current but this doesnt seem possible to do in the library. Am I missing something?

Thanks in advance.

A: 

I would avoid having a dependency on the static HttpContext. My preferred strategy would be to extract the information from the session in the controller and pass it as parameters (or set as properties) on your data access layer/repository. If you feel that you must use the Session directly, then I would provide it to the DAL/repository in the same manner -- as a property or as a parameter. Note, however, that you are increasing the coupling between your DAL/repository and the controller. This will make it much more difficult to re-use in a non-web setting, i.e., you'd have to create a fake session just to interact with the DAL/repository if you ever needed to work with it from a windows service or console app, for example.

tvanfosson
So it better then to work with session vars in the controller instead?
Yes. Your controllers are already coupled (necessarily) to the web context so you're not introducing any new couplings. Your data layer shouldn't know (or care) about where it's parameters are coming from. It shouldn't know that it's being used by a web application -- precisely because you may need it to work with some offline provisioning or data collection processes that don't have a web context.
tvanfosson