Skip to content

Instantly share code, notes, and snippets.

@aliozgur
Last active May 21, 2018 16:43
Show Gist options
  • Save aliozgur/b8859630818871d4886e98eff7644007 to your computer and use it in GitHub Desktop.
Save aliozgur/b8859630818871d4886e98eff7644007 to your computer and use it in GitHub Desktop.
GoF-Singleton
/// <summary>
/// Singleton class
/// </summary>
public sealed class SiteStructure
{
/// <summary>
/// Static instance property
/// </summary>
/// <value>The instance.</value>
public static SiteStructure Instance { get { return Nested._instance; } }
/// <summary>
/// Static constructor, needed for thread safety
/// </summary>
static SiteStructure(){}
/// <summary>
/// Private constructor. Should be private because Singleton
/// instances should not be created by consumers. Plus singleton
/// constructor has no parameters
/// </summary>
private SiteStructure()
{
//TODO : Singleton instance specific initialization
}
/// <summary>
/// Nested class, needed for lazy initialization
/// </summary>
private class Nested
{
/// <summary>
/// Static constructor
/// </summary>
static Nested(){}
/// <summary>
/// Internally accessible singleton instance field.
/// </summary>
internal static readonly SiteStructure _instance = new SiteStructure();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment