This is one of the ways to implement
singleton behavior without having a static class:
class Singleton {
public Singleton() { }
public static Singleton Instance {
get {
if (SingleInstance == null)
SingleInstance = new Singleton();
return SingleInstance;
}
}
public int FirstProperty { get; set; }
public string SecondProperty { get; set; }
public void Run() { }
private static Singleton SingleInstance;
}
All access if performed via static
Singleton.Instance
which guarantee both global access and uniqueness (withing Application Domain).
For static data it's very important to secure thread safety using locking, in case of more than one thread having access to the singleton.
Alternatively,
volatile keyword can be used.
See:
http://msdn.microsoft.com/en-us/library/x13ttww7(v=VS.100).aspx[
^],
http://www.dotnetperls.com/volatile[
^].
—SA