diff --git a/src/Umbraco.Core/DisposableObject.cs b/src/Umbraco.Core/DisposableObject.cs deleted file mode 100644 index b2c150f96c..0000000000 --- a/src/Umbraco.Core/DisposableObject.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System; - -namespace Umbraco.Core -{ - /// - /// Abstract implementation of IDisposable. - /// - /// - /// This is for objects that DO have unmanaged resources. Use - /// 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. - /// - 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() - { } - } -} diff --git a/src/Umbraco.Core/Logging/LogProfiler.cs b/src/Umbraco.Core/Logging/LogProfiler.cs index b80e40942a..74dae545b4 100644 --- a/src/Umbraco.Core/Logging/LogProfiler.cs +++ b/src/Umbraco.Core/Logging/LogProfiler.cs @@ -41,7 +41,7 @@ namespace Umbraco.Core.Logging } // a lightweight disposable timer - private class LightDisposableTimer : DisposableObject + private class LightDisposableTimer : DisposableObjectSlim { private readonly Action _callback; private readonly Stopwatch _stopwatch = Stopwatch.StartNew(); diff --git a/src/Umbraco.Core/Logging/VoidProfiler.cs b/src/Umbraco.Core/Logging/VoidProfiler.cs index a33f1b2444..24eb8e81c3 100644 --- a/src/Umbraco.Core/Logging/VoidProfiler.cs +++ b/src/Umbraco.Core/Logging/VoidProfiler.cs @@ -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() { } diff --git a/src/Umbraco.Core/Persistence/UmbracoDatabaseFactory.cs b/src/Umbraco.Core/Persistence/UmbracoDatabaseFactory.cs index 681eb1232e..dc86ff060c 100644 --- a/src/Umbraco.Core/Persistence/UmbracoDatabaseFactory.cs +++ b/src/Umbraco.Core/Persistence/UmbracoDatabaseFactory.cs @@ -24,7 +24,7 @@ namespace Umbraco.Core.Persistence /// // 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 _mappers; private readonly ILogger _logger; diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 08a2c552cb..79c3f5a2aa 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -561,7 +561,6 @@ - diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedSnapshot.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedSnapshot.cs index a0f658b93c..c7be2e6be0 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedSnapshot.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/PublishedSnapshot.cs @@ -51,7 +51,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache return new ForcedPreviewObject(); } - private class ForcedPreviewObject : DisposableObject + private class ForcedPreviewObject : DisposableObjectSlim { protected override void DisposeResources() { } diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshot.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshot.cs index 2ceced75eb..3f5c1aa4d5 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshot.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshot.cs @@ -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; diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index 9a9d966213..c67c1da02d 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -16,7 +16,7 @@ namespace Umbraco.Web /// /// Class that encapsulates Umbraco information of a specific HTTP request /// - public class UmbracoContext : DisposableObject, IDisposeOnRequestEnd + public class UmbracoContext : DisposableObjectSlim, IDisposeOnRequestEnd { private readonly IGlobalSettings _globalSettings; private readonly Lazy _publishedSnapshot; diff --git a/src/Umbraco.Web/UmbracoContextFactory.cs b/src/Umbraco.Web/UmbracoContextFactory.cs index 86b8740931..a4acd49f1e 100644 --- a/src/Umbraco.Web/UmbracoContextFactory.cs +++ b/src/Umbraco.Web/UmbracoContextFactory.cs @@ -19,7 +19,7 @@ namespace Umbraco.Web /// 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; } } -} \ No newline at end of file +} diff --git a/src/Umbraco.Web/UmbracoContextReference.cs b/src/Umbraco.Web/UmbracoContextReference.cs index be0458c3a6..6c4ac7e54a 100644 --- a/src/Umbraco.Web/UmbracoContextReference.cs +++ b/src/Umbraco.Web/UmbracoContextReference.cs @@ -12,7 +12,7 @@ namespace Umbraco.Web /// it disposes the and clears the /// . /// - 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); } } -} \ No newline at end of file +}