The title is a bit complicated, but it fits my problem. I have a complex object that acts more like a service that I need to expose within the scope of a user’s session. The majority of the application will exist within a page or two and numerous ajax calls for dynamic interaction with the service. I’m still getting used to MVC so excuse the ignorance if the solution is easy. How do I expose an instance of the service per session to my controllers?
Thanks in advance!
Also see this SO question: How does the session state work in MVC 2.0?
That answer contains a nice code sample such as the following about accesssing per-user session state from a controller class.
You can use regular ASP.NET Session state to store a complex object for a particular user.
You can store anything in session state, including your “complex object” value.
MSDN Session State quote:
The following quotes from Scott Guthrie (a Corporate Vice President in the Microsoft Developer Division) support it use of regular session state in MVC:
Scottgu Quotes about MVC & Session State support:
— http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx
— http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx