kala-tamin Maintaining state and data context between requests

Maintaining state and data context between requests

I have a EF4/ASP.NET web application that is structured to use POCOs and generic repositories, based essentially on this excellent article.

The application is relatively sophisticated with one page that involves selection and linking of multiple entities to build up a complex user profile. This requires access to multiple entity types (20 or so) and associated repositories across multiple posts.

When a repository is first accessed it uses the existing data context if exists, else it creates a new context. The problem is that if the lifetime of the context is only per-request (as suggested in the article) then you have to deal with multiple contexts and the complexity around detaching and attaching entities from contexts.

My solution is to share the context between posts by creating a single View Model that includes all required repositories (initialised to share the same context) plus any associated data and store this model in a Session variable, retrieving from Session on subsequent page requests. Therefore maintaining the same context across all posts until the profile is saved.

This works fine BUT I am concerned that I don't actually know exactly what is stored in the model session variable or more importantly the size of the Session variable.

So two questions I suppose: firstly should I look for a better solution to handle the shared context across posts issue (any suggestions welcome)? And secondly what is actually stored in the Session when it includes a repository plus context?

How can I get the client side date and currency formats?


When to use Singleton vs Transient vs Request using Ninject and MongoDB
Rick Strahl covered a very similar topic using Linq 2 SQL back in early 2008...
ASP.NET MVC Registration With Captcha
ASP.NET MVC: Why is `ToMvcHtmlString` not public?
Its quite a long read and i have never implemented it, so cannot recommend it.

What is a good strategy for dealing with large javascript code in asp.net MVC projects?
It looks like a lengthy job to implement..
How to NOT route files & directories to ASP.NET MVC
I am in a similar position to yourself, which is why i came across this post..
Object gets disconnected from nHibernate session after TryUpdateModel is called
I do wonder if just instantiating the repositories where necessary is the way to go, and let sql server manage the connection pooling (assuming that you are using sql server of course).
Validating that a form input is not empty

78 out of 100 based on 23 user ratings 998 reviews