Reputation: 17819
In StructureMap, how can I release and dispose al Http-scoped objects on a specific Container instance? For the default intance in Object Factory, I can execute the method ReleaseAndDisposeAllHttpScopedObjects()
, but the Container class and the IContainer interface doesn't seem to have such method.
Upvotes: 5
Views: 1856
Reputation: 29811
If you look at the internals of ObjectFactory.ReleaseAndDisposeAllHttpScopedObjects
, you can see that it is a conveniency method implemented like this:
public static void ReleaseAndDisposeAllHttpScopedObjects()
{
HttpContextLifecycle.DisposeAndClearAll();
}
IE. You can invoke the HttpContextLifecycle.DisposeAndClearAll
method to clear the objects.
Edit: Since the HttpContextLifecycle is global and not per container, I think that a nested container approach would be the solution to gain more fine grained control over the object lifetime during a Http Request.
Upvotes: 6