Closed pmdevers closed 11 years ago
Instead of initialize DbContext in Application_Start, try it in Init(). Also, you need to create an private instance WebDbContextStorage inside MvcApplication (Global.asax.cs):
public class MvcApplication : System.Web.HttpApplication { // other code...
private WebDbContextStorage _storage;
public override void Init()
{
base.Init();
_storage = new WebDbContextStorage(this);
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
DbContextInitializer.Instance().InitializeDbContextOnce(() =>
{
DbContextInitializer.InitStorage(_storage);
DbContextInitializer.Init(new[] { Server.MapPath("~/bin/[mapping-assembly-name].dll") });
});
}
// other code...
}
Yes thanks that was it Great Work
Could you please help me with the following issue.
I have a web application using EF5 Code First with your Repository Pattern. But when using the WebDbContextStorage like this in the Application_Start()
DbContextManager.Init("Default"); DbContextManager.InitStorage(new WebDbContextStorage(this));
When the app pool is running in Integrated Mode i recieve the following error message.
Object reference not set to an instance of an object.
when running in classic mode it is working fine.
When switching back to SimpleContextStorage it is also working fine for a single user.