using System.Threading; namespace Opsoft.NetCore.O3App.Shared { internal class Singleton where T : class, new() { private static T _instance; private static object _syncRoot = new object(); public static T Instance { get { T instance = _instance; if (instance == null) { lock (_syncRoot) { instance = Volatile.Read(ref _instance); if (instance == null) { instance = new T(); } Volatile.Write(ref _instance, instance); return instance; } } return instance; } } } }