You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace DataVAPI.Tool
- {
- /// <summary>
- /// 单例对象基类
- /// </summary>
- /// <typeparam name="T"></typeparam>
- public class Singleton<T> where T : new()
- {
- private static object _async = new object();
-
- private static T _instance;
-
- static readonly Lazy<T> instance = new();
- /// <summary>
- /// 获取实例
- /// </summary>
- /// <returns></returns>
- public static T GetInstance()
- {
- return instance.Value;
- //lock (_async)
- //{
- // if (null == _instance)
- // {
- // _instance = Activator.CreateInstance<T>();
- // }
- // return _instance;
- //}
- }
- }
- }
|