使用StructureMap时释放ObjectContext

时间:2011-02-16 15:51:20

标签: entity-framework-4 dependency-injection structuremap objectcontext

1 个答案:

答案 0 :(得分:2)

试试吧

For(typeof(WebEntities)).LifecycleIs(InstanceScope.Hybrid);

<强> Global.asax中

protected void Application_EndRequest(object sender, EventArgs e) {
    ObjectFactory.ReleaseAndDisposeAllHttpScopedObjects();
}

每次进行访问时,StructureMap都会存储上下文

var db = ObjectFactory.GetInstance<WebEntities>();