liveBook · Manning

Singleton pattern

The Singleton pattern restricts a type or component to one shared instance within a defined scope and provides a way to access that instance.

How 7 Manning books explain it

ASP.NET Core in Action, 3e

A singleton pattern is a creational design pattern that ensures a service or object has one shared instance for the relevant application lifetime.

How it is used
Uses singleton lifetime to share a service across requests in ASP.NET Core dependency injection.
How deep it goes
Explains registration, instance reuse, thread safety, and captive dependencies without implementing the pattern from scratch.
Examples
Traces shared DataContext row counts and registers a preconstructed EmailServerSettings object.
What you can do after
Apply it via ASP.NET Core dependency injection and recognize lifetime and thread-safety risks.

Read how ASP.NET Core in Action, 3e explains Singleton pattern →

Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform

A singleton pattern is a design pattern in which a resource or set of resources has one authoritative instance within a system.

How it is used
Deploys unique, environment-specific infrastructure resources together when one authoritative configuration is sufficient.
How deep it goes
Defines the pattern, demonstrates a GCP configuration, and defers detailed modular decomposition to factory, builder, and composite patterns.
Examples
Uses a GCP project, database network, MySQL server template, three-server group, and a testing workflow for an application server.
What you can do after
Operate/configure a small set of unique infrastructure resources from one static configuration and one deployment command.

Read how Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform explains Singleton pattern →

Machine Learning Platform Engineering

The singleton pattern restricts a component to one shared instance and provides a common access point to it.

How it is used
Reuses an initialized RAG core across synchronous test queries to avoid repeated embedding-model and vector-index setup.
How deep it goes
Shows a module-level cached instance, an async initialization getter, and a synchronous query wrapper; does not elaborate broader singleton variants.
Examples
Uses a Python RAG assistant with a cached core instance and an asyncio.run() query wrapper.
What you can do after
Build it from scratch as a cached async getter paired with a synchronous testing interface.

Read how Machine Learning Platform Engineering explains Singleton pattern →

Software Design for Python Programmers

The Singleton Design Pattern is a creational design pattern that restricts a class to at most one object instance and provides access to that instance.

How it is used
Models application architecture that must provide one shared object, such as a printer spooler or executive pass.
How deep it goes
Explains lazy creation, access control, copy prevention, deletion, and multithreaded race conditions through Python examples.
Examples
Uses PrintSpooler, ExecutivePass, global state, copying, explicit construction, deletion, and reference assignment.
What you can do after
Build it from scratch by controlling construction, access, copying, and replacement in a Python singleton class.

Read how Software Design for Python Programmers explains Singleton pattern →

High Performance Unity Game Development

A singleton is a pattern that restricts a class to one shared instance and provides centralized access to it.

How it is used
Uses a singleton to make a Unity game-loop controller accessible from menus and the gameplay board.
How deep it goes
Defines shared access and explains menu transitions and logic boundaries, but does not provide instance-enforcement code.
Examples
Shows a Game.Instance game-over call and separate asset-manager singletons for bundles, resources, and addressables.
What you can do after
Apply it via Unity’s Game.Instance to reach a shared controller while keeping gameplay logic independent of it.

Read how High Performance Unity Game Development explains Singleton pattern →

Object-Oriented Software Design in C++

The Singleton design pattern is a creational design pattern that restricts a class to one instance and provides a controlled access point to it.

How it is used
Uses a controlled access point when an application must manage at most one shared object.
How deep it goes
Explains construction, copying, lazy creation, deletion, and multithreading risks, but defers race-condition solutions.
Examples
Demonstrates printer spooling, a stadium executive pass, global copies, and repeated obtain-delete-obtain calls.
What you can do after
Build a C++ singleton with private construction, disabled copying, lazy creation, static access, and deletion-aware reuse.

Read how Object-Oriented Software Design in C++ explains Singleton pattern →

AI-Powered Developer: Build software with ChatGPT and Copilot

The Singleton Pattern is a software design pattern that restricts a class to one instance and provides a global access point to it.

How it is used
Coordinates one shared database connection while supporting application-wide access and replaceable persistence components.
How deep it goes
Defines the pattern and implements instance protection, connection creation, session generation, and application wiring.
Examples
Uses a DatabaseConnection class with PostgreSQL settings, SQLAlchemy sessions, and an application entry point that selects a repository.
What you can do after
Operate/configure a shared SQLAlchemy database connection using environment variables and integrate it with a repository-based application.

Read how AI-Powered Developer: Build software with ChatGPT and Copilot explains Singleton pattern →

Also covered in

What to know first

Related concepts

Questions about Singleton pattern

What is Singleton pattern?

The Singleton pattern restricts a type or component to one shared instance within a defined scope and provides a way to access that instance.

Which Manning books explain Singleton pattern?

ASP.NET Core in Action, 3e, Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform, Machine Learning Platform Engineering, Software Design for Python Programmers, High Performance Unity Game Development, Object-Oriented Software Design in C++ and AI-Powered Developer: Build software with ChatGPT and Copilot.

What should I know before learning Singleton pattern?

Manning books that teach Singleton pattern usually introduce design pattern, constructor method, object and static field first.

What kinds of Singleton pattern are there?

Kinds of Singleton pattern include cluster singleton.

What is Singleton pattern a kind of?

Singleton pattern is a kind of design pattern. A design pattern is a reusable, general solution structure for a recurring software design problem.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.