It is simplest, thread-safe solution with lazy initialization, that everyone can understand.
Example pull from here https://rubikscode.net/2017/06/11/different-ways-to-implement-singleton-in-net-and-make-people-hate-you-along-the-way/ But also see this Jon Skeets http://csharpindepth.com/Articles/General/Singleton.aspx#lazy
- don't do if null check
- don't use locks
- use lazy and static class / static constructor
namespace SingletonExamples
{
/// <summary>
/// Solution using Lazy implementation.
/// </summary>
public class SingletonLazy
{
private static readonly Lazy<SingletonLazy> instance =
new Lazy<SingletonLazy>(() => new SingletonLazy());
public static SingletonLazy Instance { get { return instance.Value; } }
private SingletonLazy()
{
}
}
}