How Do You Structure Your Singletons?
Background I'll skip over the discussion about why many people hate singletons (that's a whole separate can of worms, but worth mentioning) because in the end, it's not going to get rid of them. A singleton is a design pattern that ensures only one instance of the singleton object can ever be constructed. Often, singletons are made to be "globally accessible" in an application (although, I'm still not confident that this is actually part of the definition of a singleton). There are a handful of different ways to implement singletons... so what are they? The Not-Thread-Safe-Singleton With singletons, the main goal is to ensure that only one instance can be created. Below is a snippet of singleton code that works, but is not guaranteed in a multi-threaded environment: internal class NotThreadSafeSingleton { private static NotThreadSafeSingleton _instance; /// /// Prevents…