Application_BeginRequest で dbContext をインスタンス化し、Application_EndRequest で破棄する Entity Framework 4.1 で新しい MVC3 プロジェクトを実装しようとしています。
protected virtual void Application_BeginRequest()
{
HttpContext.Current.Items["_EntityContext"] = new EntityContext();
}
protected virtual void Application_EndRequest()
{
var entityContext = HttpContext.Current.Items["_EntityContext"] as EntityContext;
if (entityContext != null)
entityContext.Dispose();
}
EntityContext クラスは次のように定義されます。
public class EntityContext : MyEntities, IDisposable
{
**//should this be static?**
public static EntityContext Current
{
get { return HttpContext.Current.Items["_EntityContext"] as EntityContext; }
}
void IDisposable.Dispose()
{
Current.Dispose();
}
私の質問は、現在のプロパティを静的として定義すると、マルチユーザー シナリオで問題が発生しますか?