Removes DisposableObject and uses DisposableObjectSlim where necessary, renames Nul to Null
This commit is contained in:
@@ -1,64 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Abstract implementation of IDisposable.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is for objects that DO have unmanaged resources. Use <see cref="DisposableObjectSlim"/>
|
||||
/// for objects that do NOT have unmanaged resources, and avoid creating a finalizer.
|
||||
///
|
||||
/// Can also be used as a pattern for when inheriting is not possible.
|
||||
///
|
||||
/// See also: https://msdn.microsoft.com/en-us/library/b1yfkh5e%28v=vs.110%29.aspx
|
||||
/// See also: https://lostechies.com/chrispatterson/2012/11/29/idisposable-done-right/
|
||||
///
|
||||
/// Note: if an object's ctor throws, it will never be disposed, and so if that ctor
|
||||
/// has allocated disposable objects, it should take care of disposing them.
|
||||
/// </remarks>
|
||||
public abstract class DisposableObject : IDisposable
|
||||
{
|
||||
private readonly object _locko = new object();
|
||||
|
||||
// gets a value indicating whether this instance is disposed.
|
||||
// for internal tests only (not thread safe)
|
||||
public bool Disposed { get; private set; }
|
||||
|
||||
// implements IDisposable
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
// finalizer
|
||||
~DisposableObject()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
// can happen if the object construction failed
|
||||
if (_locko == null)
|
||||
return;
|
||||
|
||||
lock (_locko)
|
||||
{
|
||||
if (Disposed) return;
|
||||
Disposed = true;
|
||||
}
|
||||
|
||||
DisposeUnmanagedResources();
|
||||
|
||||
if (disposing)
|
||||
DisposeResources();
|
||||
}
|
||||
|
||||
protected abstract void DisposeResources();
|
||||
|
||||
protected virtual void DisposeUnmanagedResources()
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ namespace Umbraco.Core.Logging
|
||||
}
|
||||
|
||||
// a lightweight disposable timer
|
||||
private class LightDisposableTimer : DisposableObject
|
||||
private class LightDisposableTimer : DisposableObjectSlim
|
||||
{
|
||||
private readonly Action<long> _callback;
|
||||
private readonly Stopwatch _stopwatch = Stopwatch.StartNew();
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Umbraco.Core.Logging
|
||||
public void Stop(bool discardResults = false)
|
||||
{ }
|
||||
|
||||
private class VoidDisposable : DisposableObject
|
||||
private class VoidDisposable : DisposableObjectSlim
|
||||
{
|
||||
protected override void DisposeResources()
|
||||
{ }
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Umbraco.Core.Persistence
|
||||
/// </remarks>
|
||||
// TODO: these comments are not true anymore
|
||||
// TODO: this class needs not be disposable!
|
||||
internal class UmbracoDatabaseFactory : DisposableObject, IUmbracoDatabaseFactory
|
||||
internal class UmbracoDatabaseFactory : DisposableObjectSlim, IUmbracoDatabaseFactory
|
||||
{
|
||||
private readonly Lazy<IMapperCollection> _mappers;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
@@ -561,7 +561,6 @@
|
||||
<Compile Include="DictionaryExtensions.cs" />
|
||||
<Compile Include="Dictionary\ICultureDictionary.cs" />
|
||||
<Compile Include="Dictionary\ICultureDictionaryFactory.cs" />
|
||||
<Compile Include="DisposableObject.cs" />
|
||||
<Compile Include="Logging\DisposableTimer.cs" />
|
||||
<Compile Include="EmailSender.cs" />
|
||||
<Compile Include="Enum.cs" />
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
return new ForcedPreviewObject();
|
||||
}
|
||||
|
||||
private class ForcedPreviewObject : DisposableObject
|
||||
private class ForcedPreviewObject : DisposableObjectSlim
|
||||
{
|
||||
protected override void DisposeResources()
|
||||
{ }
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
return new ForcedPreviewObject(this, preview, callback);
|
||||
}
|
||||
|
||||
private class ForcedPreviewObject : DisposableObject
|
||||
private class ForcedPreviewObject : DisposableObjectSlim
|
||||
{
|
||||
private readonly PublishedSnapshot _publishedSnapshot;
|
||||
private readonly bool _origPreview;
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Umbraco.Web
|
||||
/// <summary>
|
||||
/// Class that encapsulates Umbraco information of a specific HTTP request
|
||||
/// </summary>
|
||||
public class UmbracoContext : DisposableObject, IDisposeOnRequestEnd
|
||||
public class UmbracoContext : DisposableObjectSlim, IDisposeOnRequestEnd
|
||||
{
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly Lazy<IPublishedSnapshot> _publishedSnapshot;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Umbraco.Web
|
||||
/// </summary>
|
||||
public class UmbracoContextFactory : IUmbracoContextFactory
|
||||
{
|
||||
private static readonly NulWriter NulWriterInstance = new NulWriter();
|
||||
private static readonly NullWriter NullWriterInstance = new NullWriter();
|
||||
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly IPublishedSnapshotService _publishedSnapshotService;
|
||||
@@ -65,7 +65,8 @@ namespace Umbraco.Web
|
||||
if (currentUmbracoContext != null)
|
||||
return new UmbracoContextReference(currentUmbracoContext, false, _umbracoContextAccessor);
|
||||
|
||||
httpContext = httpContext ?? new HttpContextWrapper(HttpContext.Current ?? new HttpContext(new SimpleWorkerRequest("nul.aspx", "", NulWriterInstance)));
|
||||
|
||||
httpContext = httpContext ?? new HttpContextWrapper(HttpContext.Current ?? new HttpContext(new SimpleWorkerRequest("null.aspx", "", NullWriterInstance)));
|
||||
|
||||
var umbracoContext = CreateUmbracoContext(httpContext);
|
||||
_umbracoContextAccessor.UmbracoContext = umbracoContext;
|
||||
@@ -74,9 +75,9 @@ namespace Umbraco.Web
|
||||
}
|
||||
|
||||
// dummy TextWriter that does not write
|
||||
private class NulWriter : TextWriter
|
||||
private class NullWriter : TextWriter
|
||||
{
|
||||
public override Encoding Encoding => Encoding.UTF8;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Umbraco.Web
|
||||
/// it disposes the <see cref="UmbracoContext"/> and clears the
|
||||
/// <see cref="IUmbracoContextAccessor"/>.</para>
|
||||
/// </remarks>
|
||||
public class UmbracoContextReference : IDisposable
|
||||
public class UmbracoContextReference : IDisposable //fixme - should we inherit from DisposableObjectSlim?
|
||||
{
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private bool _disposed;
|
||||
@@ -57,4 +57,4 @@ namespace Umbraco.Web
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user