We live in open source world... So, let it be same for knowledge !!
Note :- The implementations and code snippets are from my learning and knowledge repository. I am putting in public domain to be used by anyone. See creative commons License for more details.

Pages

Friday, April 26, 2013

Implementing Singleton using Static Constructor

There is another way to implement Singleton design pattern by using static constructor. Static constructors in C# are specified to execute only when an instance of the class is created or a static member is referenced, and to execute only once per AppDomain.
This is a thread-safe implementation and there are other ways to implement Singleton but this for seems to crater most of my requirement. It is highly unlikely that I needed a static variable in the singleton.