using System;
namespace Umbraco.Web
{
///
/// Represents a reference to an instance.
///
///
/// A reference points to an and it may own it (when it
/// is a root reference) or just reference it. A reference must be disposed after it has
/// been used. Disposing does nothing if the reference is not a root reference. Otherwise,
/// it disposes the and clears the
/// .
///
public class UmbracoContextReference : IDisposable //fixme - should we inherit from DisposableObjectSlim?
{
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private bool _disposed;
///
/// Initializes a new instance of the class.
///
internal UmbracoContextReference(UmbracoContext umbracoContext, bool isRoot, IUmbracoContextAccessor umbracoContextAccessor)
{
UmbracoContext = umbracoContext;
IsRoot = isRoot;
_umbracoContextAccessor = umbracoContextAccessor;
}
///
/// Gets the .
///
public UmbracoContext UmbracoContext { get; }
///
/// Gets a value indicating whether the reference is a root reference.
///
///
///
///
public bool IsRoot { get; }
///
public void Dispose()
{
if (_disposed)
return;
_disposed = true;
if (IsRoot)
{
UmbracoContext.Dispose();
_umbracoContextAccessor.UmbracoContext = null;
}
GC.SuppressFinalize(this);
}
}
}