如何在Container实例上释放和处置所有Http范围的对象?

Gui*_*rez 5 c# structuremap httpcontext

在StructureMap中,如何在特定的Container实例上释放和处理Http范围的对象?对于Object Factory中的默认intance,我可以执行该方法ReleaseAndDisposeAllHttpScopedObjects(),但Container类和IContainer接口似乎没有这样的方法.

PHe*_*erg 6

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

public static void ReleaseAndDisposeAllHttpScopedObjects()
{
    HttpContextLifecycle.DisposeAndClearAll();
}
Run Code Online (Sandbox Code Playgroud)

IE浏览器.您可以调用该HttpContextLifecycle.DisposeAndClearAll方法来清除对象.

编辑:由于HttpContextLifecycle是全局的而不是每个容器,我认为嵌套容器方法将是在Http请求期间获得对对象生命周期的更细粒度控制的解决方案.