Skip to content

dependency-injection-guidelines.md blanket advice on avoiding singletons is misleading #49140

@andriy-genndy

Description

@andriy-genndy

Describe the issue or suggestion

The following PR introduced new guidelines specifically around using Singleton lifetime in DI-centric application designs: #47991

The guideline clearly sides with "make everything transient by default" as the safer (major emphasis) and more performant (the last bullet point) approach.

IMO this seems to be giving a dangerously blanket advice to 6-8 million .net developers, nearly-encouraging them to swipe state management problems under the carpet of transient lifetime, instead of striving for clean stateless design and zero-allocations as seems to be the default guideline in the Java/Spring community. I understand the pragmatism of giving .net developers what the author likely saw as a safe "lowest common denominator" approach that'd keep an average LOB development team out of trouble, and in the legacy codebases with no design governance making everything transient by default may indeed be the only viable survival strategy, but framing it as THE best practice for all codebases (no qualification), makes it hard to impossible to advocate for clean stateless-by-default designs now that "Microsoft said it's a bad idea".

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions