Posted 03 Apr 2012 Link to this post
public
class
ContextFactory
{
static
NorthwindContext GetContextPerRequest()
HttpContext httpContext = HttpContext.Current;
if
(httpContext ==
null
)
return
new
NorthwindContext();
}
else
int
contextId = Thread.CurrentContext.ContextID;
hashCode = httpContext.GetHashCode();
string
key =
.Concat(hashCode, contextId);
NorthwindContext context = httpContext.Items[key]
as
NorthwindContext;
(context ==
context =
httpContext.Items[key] = context;
context;
Posted 09 Apr 2012 Link to this post
You have probably seen the old version of this example, available with Q3 2011 of OpenAccess SDK. In the latest release of the SDK (available on our web site for free) you can check the refactored and renamed sample now called "Managing OpenAccess Context" in the ASP.NET category. There, you will find the following way of disposing the OpenAccessContext in case you have chosen to store it in the HttpContext:
Global : HttpApplication
protected
void
Application_EndRequest(
object
sender, EventArgs e)
NorthwindContext context = ContextFactory.GetContextPerRequest();
(context !=
context.Dispose();