Created
November 1, 2013 21:15
-
-
Save RobertBonham/7272067 to your computer and use it in GitHub Desktop.
Singleton done properly for 99% of needs Jon Skeet (http://pluralsight.com/training/Courses/TableOfContents/csharp-design-strategies)
This file contains hidden or 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
public class Singleton | |
{ | |
private static readonly Singleton instance = new Singleton(); | |
// Empty static ctor forces laziness | |
static Singleton() | |
{} | |
private Singleton() | |
{ | |
// STuff that must only happen once | |
Console.WriteLine("Singleton Constructor"); | |
} | |
public static Singleton Instance { get { return instance; } } | |
public static void SayHi() | |
{ | |
Console.WriteLine("Hi"); | |
} | |
public void DoSomething() | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment