using
System;
public class SingletonTemplate < T >
{
private static object _locker = new object ();
private static SingletonTemplate < T > _obj = null ;
private static T _instance;
private SingletonTemplate()
{
_instance = Activator.CreateInstance < T > ();
}
public static T Instance
{
get
{
if (_obj == null )
{
lock (_locker)
{
if (_obj == null )
{
_obj = new SingletonTemplate < T > ();
}
}
}
return _instance;
}
}
}
public class SingletonTemplate < T >
{
private static object _locker = new object ();
private static SingletonTemplate < T > _obj = null ;
private static T _instance;
private SingletonTemplate()
{
_instance = Activator.CreateInstance < T > ();
}
public static T Instance
{
get
{
if (_obj == null )
{
lock (_locker)
{
if (_obj == null )
{
_obj = new SingletonTemplate < T > ();
}
}
}
return _instance;
}
}
}