I use the singleton pattern in a lot of places, sometimes the constructor does nothing, other times it's initialising things.
I wondered if there was a way to set up an abstract class to minimise my code repetition a bit, i.e. I don't need public static readonly Singleton _Instance = new Singleton(); in every single class, just one base class.
I understand interfaces are not an option.
I've tried using the following (taken from here);
public abstract class Singleton<T> where T : new()
{
static Singleton()
{
}
private static readonly T _Instance = new T();
public static T Instance
{
get { return _Instance; }
}
}
The problem with this is that I can't override the constructor for the cases where I need to initialise things. Is what I'm trying to do even possible? Or should I just keep doing what I'm doing and not worry about a base singleton class?