wpf2021. 8. 24. 12:13

 public abstract class Singleton<T> where T : class
    {
        private static readonly Lazy<T> LazyInstance =
            new Lazy<T>(CreateInstanceOfT, LazyThreadSafetyMode.ExecutionAndPublication);

        public static T Instance
        {
            get
            {
                return Singleton<T>.LazyInstance.Value;
            }
        }

        private static T CreateInstanceOfT()
        {
            return Activator.CreateInstance(typeof(T), true) as T;
        }
    }

 

출처 : http://egloos.zum.com/sweeper/v/3157853

Posted by 동동(이재동)