2013-04-05 34 views

回答

6

如果你看看ObjectFactory.ReleaseAndDisposeAllHttpScopedObjects的内部,你可以看到它是这样实现的方便性方法:

public static void ReleaseAndDisposeAllHttpScopedObjects() 
{ 
    HttpContextLifecycle.DisposeAndClearAll(); 
} 

IE。您可以调用HttpContextLifecycle.DisposeAndClearAll方法清除对象。

编辑:由于HttpContextLifecycle是全局的,而不是每个容器,我认为一个nested container方法将是一个解决方案,以获得更好的Http请求期间的对象生存期的细粒度控制。

+0

谢谢,但它似乎处置所有的Http作用域对象,不仅仅是来自当前容器实例的对象。 – 2013-04-05 20:30:41

+0

@ guillegr123 - 'HttpContextLifecycle'是全局的,而不是每个容器。 – PHeiberg 2013-04-05 20:34:35

+0

如果你想控制'HttpRequest'中的特定对象的生命周期,我认为你应该使用[嵌套容器](http://codebetter.com/jeremymiller/2010/02/10/nested-containers-in- structuremap-2-6-1 /)方法。 – PHeiberg 2013-04-05 20:40:22

相关问题