Singleton.cs 389 B

12345678910111213141516
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Aitex.Core.Util
  6. {
  7. [Serializable]
  8. public class Singleton<T> where T : class, new()
  9. {
  10. private static readonly Lazy<T> lazy =
  11. new Lazy<T>(() => new T(), true);
  12. public static T Instance => lazy.Value;
  13. }
  14. }