wpf
싱글톤 쓰기
동동(이재동)
2021. 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;
}
}