I use Unity to inject dependencies, but the idea is the same:
protected void Application_BeginRequest() { var childContainer = this.Container.CreateChildContainer(); HttpContext.Current.Items["container"] = childContainer; this.ControllerFactory.RegisterTypes(childContainer); } protected void Application_EndRequest() { var container = HttpContext.Current.Items["container"] as IUnityContainer; if (container != null) { container.Dispose(); } }
A container is responsible for setting up several things, one of which is the data context. It works like a charm. I did not perform load balancing, but I canβt imagine that you are facing problems. The query gets its own context, which wraps one user connecting to the database. Nothing else that using the old school ADO.NET to access data.
source share