Reverts how UmbracoContextReference works

This commit is contained in:
Shannon
2020-02-19 15:46:54 +11:00
parent 5cb5585574
commit 04c620d76e
2 changed files with 7 additions and 5 deletions

View File

@@ -14,22 +14,24 @@ namespace Umbraco.Web
/// </remarks>
public class UmbracoContextReference : IDisposable //fixme - should we inherit from DisposableObjectSlim?
{
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private bool _disposed;
/// <summary>
/// Initializes a new instance of the <see cref="UmbracoContextReference"/> class.
/// </summary>
internal UmbracoContextReference(bool isRoot, IUmbracoContext umbracoContext)
internal UmbracoContextReference(IUmbracoContext umbracoContext, bool isRoot, IUmbracoContextAccessor umbracoContextAccessor)
{
IsRoot = isRoot;
UmbracoContext = umbracoContext;
_umbracoContextAccessor = umbracoContextAccessor;
}
/// <summary>
/// Gets the <see cref="UmbracoContext"/>.
/// </summary>
public IUmbracoContext UmbracoContext { get; private set; }
public IUmbracoContext UmbracoContext { get; }
/// <summary>
/// Gets a value indicating whether the reference is a root reference.
@@ -49,7 +51,7 @@ namespace Umbraco.Web
if (IsRoot)
{
UmbracoContext.Dispose();
UmbracoContext = null;
_umbracoContextAccessor.UmbracoContext = null;
}
GC.SuppressFinalize(this);

View File

@@ -77,13 +77,13 @@ namespace Umbraco.Web
{
var currentUmbracoContext = _umbracoContextAccessor.UmbracoContext;
if (currentUmbracoContext != null)
return new UmbracoContextReference(false, currentUmbracoContext);
return new UmbracoContextReference(currentUmbracoContext, false, _umbracoContextAccessor);
var umbracoContext = CreateUmbracoContext();
_umbracoContextAccessor.UmbracoContext = umbracoContext;
return new UmbracoContextReference(true, umbracoContext);
return new UmbracoContextReference(umbracoContext, true, _umbracoContextAccessor);
}
// dummy TextWriter that does not write