C-Sharp Design Patterns Singleton
This course covers the Singleton pattern, one of the most well-known but also most misused design patterns.
Design patterns are like individual tools that one can add to their toolbox as a software developer. They don't take long to introduce, but can require a lot of practice to master.
By the end of this course, you will be able to recognize situations where the Singleton pattern makes sense, and apply it—or an alternative—with confidence.
A Singleton is a class designed to allow the creation of only a single instance of itself. The class itself is responsible for enforcing this design constraint.
Sign in to read this course
A free account unlocks all 514 courses. 20 are readable without one.
What's inside
19 sections- 1 Table of Contents
- 2 Course Overview
- 3 Introduction to the Singleton pattern
- 4 Structure and characteristics of the Singleton
- 5 Naive implementation — v1 (Naive Singleton)
- 6 Implementation with lock — v2 (Thread Safe Singleton with lock)
- 7 Double Checked Locking — v3 (Best Lock)
- 8 Analysis of lock approaches
- 9 Static and Singleton Constructors
- 10 Singleton with static initialization — v4 (Less Lazy)
- 11 Singleton with nested class — v5 (Nested Lazy)
- 12 Analysis of approaches by static constructor
- 13 Singleton with Lazy<T> — v6 (Recommended approach)
- 14 Is the Singleton an anti pattern?
- 15 Singleton vs. Static classes
- 16 Using IoC/DI Containers
- 17 Testing Considerations
- 18 Key Takeaways
- 19 Resources and references
More Testing, Patterns & Architecture courses
View all 29ASP.NET Core Clean Architecture
Implement Clean Architecture with the GloboTicket app — core, infrastructure, API, Blazor UI and testing.
Automation Testing Strategies with ASP.NET Core
Unit, integration, UI, E2E (Playwright) and performance (NBomber) testing in a CI/CD pipeline.
Unit Testing an ASP.NET Core MVC Web Application
Unit test MVC controllers with xUnit, Moq and FluentAssertions — isolation, mocking and CI/CD.
Debugging and Error Handling in ASP.NET Core
Debugging tools, error-handling middleware, Problem Details, custom exceptions and remote debugging.
Logging and Monitoring in ASP.NET Core
ILogger, structured logging, providers, scopes, source generators, health checks and OpenTelemetry.
C-Sharp 8 Design Patterns Composite
This course covers the Composite design pattern in C#. The Composite pattern provides a way to work with tree structures in a consistent manner, regardless of whether you are manipulating...
Interested in this course?
Contact us to book it or get a custom training plan for your team.