Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to release and dispose all Http-scoped objects on Container instance?

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.

like image 302
Guillermo Gutiérrez Avatar asked Apr 05 '13 17:04

Guillermo Gutiérrez


1 Answers

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.

like image 163
PHeiberg Avatar answered Nov 15 '22 17:11

PHeiberg