In NHibernate SessionFactory is said to be a heavy object and it is suggested that SessionFactory should be created once in application life span. However once we get handle to SessionFactory, we do call open() on it before doing any DB operation.
In EntityFramework we need to create an object of ObjectContext every time before doing any operation with underlying store. There is no opening as such in case of EF.
My questions is:
"Is Creating a context in EF is similar to calling Open() on SessionFactory in NHibernate?" or "Should I create ObjectContext once in application life span and share it across?"
Update: I found following link on managing ObjectContext lifespan. However in that link author mentions:
However, you shouldn’t use a static ObjectContext in an ASP.NET application, since static members have a lifespan beyond that of a single HTTP request. They’re actually bound to the lifespan of the AppDomain, which might be minutes or hours. In fact, static class members in ASP.NET are even shared between multiple threads and users of the application. Using the same ObjectContext instance from within multiple threads simultaneously can cause serious problems.
But in NHibernate we do the exact same thing. We create SessionFactory as a static field and then use the same instance across application again and again.
Is that what being suggested as a wrong practice in case of Entity Framework?