Enterprise Application Architecture with .NET Core
by Ganesan Senthilvel, Ovais Mehboob Ahmed Khan, Habib Qureshi
The singleton pattern
The singleton pattern is perhaps the most common pattern used by developers across the globe. This pattern basically defines a class for which only one (single) instance can exist.
You can have a class that is either global or static with all static methods so that you do not need to create any instance of this class and use it directly. This is okay but not considered a best practice generally, unless you are defining a stateless interface to expose an underlying OS APIs, such as subset win32 APIs or a native DLL or system library exposing its one-off APIs.
Singleton - If you want to have a stateful class whose only one instance should exist in the given software, then what you need is a singleton class. An example ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access