I need a singleton that:
public class Singleton where T : class, new()
{
private static T instance;
public static T Instance
{
get
{
if (instance == null)
{
throw new Exception("singleton needs to be initialised before use");
}
return instance;
}
}
public static void Initialise(Action initialisationAction)
{
lock(typeof(Singleton))
{
if (instance != null)
{
return;
}
instance = new T();
initialisationAction(instance);
}
}
}