Structuremap Disposing of DataContext object

后端 未结 2 1606
心在旅途
心在旅途 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条回答
  •  梦毁少年i
    2021-01-12 14:01

    No it will not Dispose it automatically, unless you use nested containers and Dispose the container holding the context instance. It's up to the creator of the context to Dispose it. The creator would usually be the part of your code calling ObjectContext.GetInstance or the root method that makes StructureMap inject a DataContext into one of your objects.

    A common practice is to create a context per HttpRequest and dispose the context at the end of the request.

提交回复
热议问题