Last active
May 21, 2018 16:43
-
-
Save aliozgur/b8859630818871d4886e98eff7644007 to your computer and use it in GitHub Desktop.
GoF-Singleton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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