Ensures that any instances created with the ManyObjectsResolverBase that have an HTTP lifetime are disposed of at the end of the request

This commit is contained in:
Shannon
2015-01-16 17:24:47 +11:00
parent 16f63b7fd9
commit c853263894

View File

@@ -237,7 +237,14 @@ namespace Umbraco.Core.ObjectResolution
// create new instances per HttpContext
if (CurrentHttpContext.Items[_httpContextKey] == null)
{
CurrentHttpContext.Items[_httpContextKey] = CreateInstances().ToArray();
var instances = CreateInstances().ToArray();
var disposableInstances = instances.OfType<IDisposable>();
//Ensure anything resolved that is IDisposable is disposed when the request termintates
foreach (var disposable in disposableInstances)
{
CurrentHttpContext.DisposeOnPipelineCompleted(disposable);
}
CurrentHttpContext.Items[_httpContextKey] = instances;
}
return (TResolved[])CurrentHttpContext.Items[_httpContextKey];