class GenericSingleton<T> where T : class, new()
{
private static T instance;
public static T GetInstance()
{
lock (typeof(T))
{
if (instance == null)
{
instance = new T();
}
return instance;
}
}
}
مثال از نحوه ی استفاده :
AutoFactory autoF = GenericSingleton<AutoFactory>.GetInstance();
منبع : http://blog.paranoidferret.com/index...leton-pattern/