Skip to content

Commit

Permalink
WAF SettingsServiceCore provides a virtual Dispose implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed May 27, 2019
1 parent 7d61542 commit 1a7b989
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Linq;
using System.Runtime.Serialization;
using System.Threading;
using System.Threading.Tasks;
using System.Waf.Applications;
using System.Waf.Applications.Services;
using System.Waf.Presentation.Services;
Expand Down Expand Up @@ -61,6 +60,7 @@ public void GetAndSaveTest()
Assert.AreEqual(3.14, testSettings2.Value);
testSettings2.Value = 72;
settingsService.Dispose();
settingsService.Dispose();

// Read the saved values with another instance
settingsService = new SettingsServiceCore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1001:Types that own disposable fields should be disposable", Justification = "<Pending>", Scope = "type", Target = "~T:System.Waf.Foundation.ThrottledAction")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Build", "CA1724:The type name Cache conflicts in whole or in part with the namespace name 'System.Net.Cache' defined in the .NET Framework. Rename the type to eliminate the conflict.", Justification = "<Pending>", Scope = "type", Target = "~T:System.Waf.Foundation.Cache`1")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = "<Pending>", Scope = "member", Target = "~M:System.Waf.Applications.Services.ISettingsService.Get``1~``0")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2214:Do not call overridable methods in constructors", Justification = "<Pending>", Scope = "member", Target = "~M:System.Waf.Applications.Services.UserSettingsBase.#ctor")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1063:Implement IDisposable Correctly", Justification = "<Pending>", Scope = "member", Target = "~M:System.Waf.Presentation.Services.SettingsServiceCore.Dispose(System.Boolean)")]

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class SettingsServiceCore : ISettingsService, IDisposable

private readonly ConcurrentDictionary<Type, Lazy<object>> settings;
private string fileName;
private volatile bool isDisposed;

/// <summary>
/// Initializes a new instance of the SettingsService.
Expand Down Expand Up @@ -140,7 +141,32 @@ private static void UpdateDocument(XDocument document, IReadOnlyList<object> set
/// </summary>
public void Dispose()
{
Save();
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Call this method from a subclass when you implement a finalizer (destructor).
/// </summary>
/// <param name="disposing">if true then dispose unmanaged and managed resources; otherwise dispose only unmanaged resources.</param>
protected void Dispose(bool disposing)
{
if (isDisposed) { return; }
isDisposed = true;

OnDispose(disposing);
if (disposing)
{
Save();
}
}

/// <summary>
/// Override this method to free, release or reset any resources.
/// </summary>
/// <param name="disposing">if true then dispose unmanaged and managed resources; otherwise dispose only unmanaged resources.</param>
protected virtual void OnDispose(bool disposing)
{
}

private void OnErrorOccurred(SettingsErrorEventArgs e)
Expand Down

0 comments on commit 1a7b989

Please sign in to comment.