csharp-di
CommunityReliable .NET DI patterns for maintainable services
Software Engineering#csharp#dotnet#di#dependency-injection#worker-service#decorator-pattern#generic-host
AuthorCloudyWing
Version1.0.0
Installs0
System Documentation
What problem does it solve?
Provides clear, opinionated guidance to avoid common dependency injection pitfalls in .NET applications, ensuring correct lifetimes, safe scoped usage, and maintainable service registration patterns.
Core Features & Use Cases
- Generic Host best practices: Directs use of Host.CreateDefaultBuilder or Host.CreateApplicationBuilder and prohibits ad-hoc BuildServiceProvider in production code.
- Worker Service (BackgroundService) patterns: Prescribes creating scopes with IServiceScopeFactory inside ExecuteAsync loops and enforcing cancellation token checks for graceful shutdown.
- Multi-implementation & Decorator strategies: Recommends keyed services for multiple implementations, IEnumerable injection for bulk consumers, and explicit decorator registration for cross-cutting concerns.
- Use Case: Implement a background order processor that safely resolves scoped order services per iteration, applies a cached repository decorator, and supports multiple notification implementations via keyed services.
Quick Start
Use Host.CreateApplicationBuilder(args) to build the host, register interfaces with scoped lifetimes, use IServiceScopeFactory inside BackgroundService loops for scoped work, and apply keyed services or decorators for multi-implementation scenarios.
Dependency Matrix
Required Modules
None requiredComponents
Standard package💻 Claude Code Installation
Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.
Please help me install this Skill: Name: csharp-di Download link: https://github.com/CloudyWing/ai-dotfiles/archive/main.zip#csharp-di Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
Agent Skills Search Helper
Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.