The Singleton design pattern is used to ensure an application never contains more than a single instance of a given type. It is often considered to be an antipattern, since the pattern’s implementation places the responsibility of enforcing the single instance behavior on the type itself. This violates the Single Responsibility Principle and references to the type’s static Instance property often result in tight coupling (see Static Cling).

An example implementation:

A better approach than the Singleton pattern is to follow the Explicit Dependencies Principle from for classes that depend on a singleton type. Use dependency injection to pass the object into the type that needs it, and configure the services/IOC container to enforce the object’s singleton lifetime behavior.


Jon Skeet on Implementing the Singleton Pattern in C#

Comments are closed.