This project is read-only.
Project Description
C# Singleton Base Class is a single, simple C# class used to implement the Singleton pattern through inheritance.

Singleton<T> holds a Lazy<T> reference to the derived-classes type which is constructed/accessed using the static Instance member proeprty. Due to limitations on generic type constraints in the CLR, a run-time check is made during construction of the instance to determine that the derived type was implemented with a single non-public constructor (which is invoked using reflection). Object construction is slower than it might be if you explicitly implemented the Singleton pattern in your class due to the use of reflection, however as the type is lazily constructed and only ever once per AppDomain, I think it is a small price to pay for explicitly implementing a type as Singleton with all of the type verification that this grants one both statically and dynamically.

Last edited Oct 10, 2012 at 7:56 PM by cshepley, version 3