DataContext对象的Structuremap处置 [英] Structuremap Disposing of DataContext object

查看:91
本文介绍了DataContext对象的Structuremap处置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想可以肯定,如果structuremap将每个请求结束后,我处理的DataContext。

下面是我的设置

<$p$p><$c$c>ForRequestedType<MyDataContext>().TheDefault.Is.OfConcreteType<MyDataContext>();
SelectConstructor&LT; MyDataContext&GT;(()=&gt;新建MyDataContext());

将structuremap自动处理我的DataContext还是需要手动调用Dispose ??


解决方案

没有它不会自动处置它,除非你使用嵌套的容器和处置容器保持上下文实例。它是由以处置它上下文的创造者。创建者通常会是您的code调用的一部分 ObjectContext.GetInstance&LT; MyDataContext方式&gt; 或使StructureMap注入一个DataContext到您的对象之一根法

一个常见的​​做法是创建每个Htt的prequest上下文,并在请求结束处置环境。

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

Here is my setup

ForRequestedType<MyDataContext>().TheDefault.Is.OfConcreteType<MyDataContext>();
SelectConstructor<MyDataContext>(() => new MyDataContext());

Will structuremap auto dispose my datacontext or do i need to call Dispose manually??

解决方案

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<MyDataContext> 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.

这篇关于DataContext对象的Structuremap处置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆