Skip to content

Commit

Permalink
Updated Singleton to use Lazy<>
Browse files Browse the repository at this point in the history
  • Loading branch information
igolets committed Aug 3, 2015
1 parent d34ae9e commit 84f7e53
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions Egorka/EgorkaSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Configuration;
using System;
using System.Configuration;
using System.Globalization;

namespace EgorkaGame.Egorka
Expand All @@ -13,27 +14,16 @@ public static EgorkaSettings Instance
{
get
{
if (_instance == null)
{
lock (Locker)
{
if (_instance == null)
{
_instance = (EgorkaSettings)ConfigurationManager.GetSection("egorkaSettings");
}
}
}

return _instance;
// read http://csharpindepth.com/articles/general/singleton.aspx for more info
return Lazy.Value;
}
}

#endregion

#region Fields

private static volatile EgorkaSettings _instance;
private static readonly object Locker = new object();
private static readonly Lazy<EgorkaSettings> Lazy = new Lazy<EgorkaSettings>(() => new EgorkaSettings());

#endregion

Expand Down

0 comments on commit 84f7e53

Please sign in to comment.