Structuremap Disposing of DataContext object

后端 未结 2 1589
心在旅途
心在旅途 2021-01-12 13:02

I wanted to be sure if structuremap will dispose my DataContext after per request ends.

Here is my setup

ForRequestedType().TheD         


        
2条回答
  •  醉梦人生
    2021-01-12 13:53

    That's what I do:

        For()
            .HybridHttpOrThreadLocalScoped()
            .Use();
    
        For()
            .HybridHttpOrThreadLocalScoped()
            .Use(o => ((BpReminders.Data.NH.UnitOfWork)o.GetInstance()).CurrentSession);
    

    and ...

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

    HybridHttpOrThreadLocalScoped uses the HttpContext when available.

    StructureMap looks after everything, then. Just remember to implement IDisposable in your classes.

提交回复
热议问题