I am trying to implement the Jon Skeet’s example
public sealed class Singleton
{
Singleton()
{
}
public static Singleton Instance
{
get
{
return Nested.instance;
}
}
class Nested
{
// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit
static Nested()
{
}
internal static readonly Singleton instance = new Singleton();
}
}
Do all your database operations in the constructor for
Singleton.Without knowing what those operations are, we can’t really provide much more help – but that’s where you should put them. Obviously that doesn’t mean creating a massive constructor – you can still split the code up into normal methods, but you need to call them from the constructor.