Jon Skeet suggests in his singleton implementation that if you require the maximum laziness for your singleton you should add a static constructor which will make the compil
When I call Singleton.Stub() the private constructor is not being hit, when I uncomment the static ctor private constuctor is always called.
It's not clear what the value of which
is here, but fundamentally you've got four cases:
Singleton.Stub
called: type initializer is guaranteed to runSingleton.Stub
not called: type initializer is guaranteed not to runSingleton.Stub
called: type initializer may run, but isn't guaranteed toSingleton.Stub
not called: type initializer may run, but isn't guaranteed toThe last two cases only differ in that if you change Singleton.Stub
to use a static field, the third case becomes "type initializer is guaranteed to run".