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