# Singleton Pattern

Record: `arch:singleton-pattern`
Kind: pattern
Layer: [Design Patterns Core](https://banes-lab.com/records/layer/design-patterns-core.md)
Severity: contextual/discouraged unless justified
Scope: object_creation, lifetime, composition root
Canonical: https://banes-lab.com/ontology#arch-singleton-pattern

## Repair

- Refactored by: Compose Single Instance at the Root, Inject It
- Detected by: static global access to a shared service
- Violated by: a global mutable instance reached from anywhere
- Measured by: global-instance reach-in count
- Enforced by: composition-root review

## requires

- [Single-Instance Need](https://banes-lab.com/records/lex/single-instance-need.md)

## reinforces

- [Controlled Instantiation](https://banes-lab.com/records/lex/controlled-instantiation.md)

## enables

- [Shared Resource Access](https://banes-lab.com/records/lex/shared-resource-access.md)

## conflicts-with

- [Global Mutable State](https://banes-lab.com/records/lex/global-mutable-state.md)

## tensions-with

- [Testability](https://banes-lab.com/records/arch/testability.md)
- [Dependency Injection](https://banes-lab.com/records/arch/dependency-injection.md)

## tensions

- [Singleton Pattern Testability](https://banes-lab.com/records/tension/singleton-pattern-testability.md)
- [Singleton Pattern Dependency Injection](https://banes-lab.com/records/tension/dependency-injection-singleton-pattern.md)
