Doing some work on abstract classes and singletons, I have come across many useful resources from StackOverflow. However, I still have a question regarding the grandchildren of singleton classes.
My singleton code looks like this, taken from the answer on How to abstract a singleton class?, looks like this:
public abstract class Singleton<T> where T : Singleton<T>
{
private static readonly Lazy<T> _instance;
static Singleton()
{
_instance = new Lazy<T>(() =>
{
try
{
// Binding flags include private constructors.
var constructor = typeof(T).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
return (T)constructor.Invoke(null);
}
catch (Exception exception)
{
throw new SingletonConstructorException(exception);
}
});
}
public static T Instance { get { return _instance.Value; } }
}
My children of this class are created with this syntax:
public class SingletonChild : Singleton<SingletonChild>
{
[code]
}
Now, my question lies here: How does one declare a child of the child class, or a grandchild of the singleton?
I believe it is one of these two, but I'm not sure which:
public class SingletonGrandChild : SingletonChild { [code] }
OR
public class SingletonGrandChild : SingletonChild<SingletonGrandChild> { [code] }
Can anyone provide some insight as to what it would be? Thanks!