namespace WWPipeLine.Commons
{
///
/// 泛型单例模式
///
///
public class SingletonProvider where T : class, new()
{
private static T _instance = null;
private static object _instanceLock = new object();
private SingletonProvider()
{
}
///
/// 用法:SingletonProvider<T>.Instance 获取该类的单例
///
public static T Instance
{
get
{
if (_instance == null)
{
lock (_instanceLock)
{
if (_instance == null)
{
_instance = new T();
}
}
}
return _instance;
}
}
}
}