/// <summary>
/// Provides functionality of creating a singleton instance of a class.
/// </summary>
/// <typeparam name="T">The class to create as a singleton. This class must have a private constructor with no parameters.</typeparam>
//AJ: http://www.codeproject.com/cs/design/GenericSingletonPattern.asp
public static class ParameterlessSingleton<T>
where T : class
{
/// <summary>
/// Static constructor for lazy instaniation.
/// </summary>
static ParameterlessSingleton()
{
}
/// <summary>
/// The singleton instance of provided type T.
/// </summary>
public static readonly T Instance =
typeof(T).InvokeMember(typeof(T).Name,
BindingFlags.CreateInstance |
BindingFlags.Instance |
BindingFlags.NonPublic,
null, null, null) as T;
}
This is an example property:
#region SingletonInstance
public static ExceptionLogger SingletonInstance
{
get
{
return Singleton<ExceptionLogger>.Instance;
}
}
#endregion