Files
Umbraco-CMS/src/Umbraco.Core/Scoping/ScopeReference.cs

31 lines
915 B
C#
Raw Normal View History

2017-05-12 14:49:44 +02:00
namespace Umbraco.Core.Scoping
{
/// <summary>
/// References a scope.
/// </summary>
/// <remarks>Should go into HttpContext to indicate there is also an IScope in context
/// that needs to be disposed at the end of the request (the scope, and the entire scopes
/// chain).</remarks>
internal class ScopeReference : IDisposeOnRequestEnd // implies IDisposable
{
2017-05-30 19:41:37 +02:00
private readonly ScopeProvider _scopeProvider;
2017-05-12 14:49:44 +02:00
2017-05-30 19:41:37 +02:00
public ScopeReference(ScopeProvider scopeProvider)
2017-05-12 14:49:44 +02:00
{
_scopeProvider = scopeProvider;
}
public void Dispose()
{
// dispose the entire chain (if any)
// reset (don't commit by default)
Scope scope;
2017-05-12 14:49:44 +02:00
while ((scope = _scopeProvider.AmbientScope) != null)
{
scope.Reset();
scope.Dispose();
}
}
}
}