dotnet-csharp-dependency-injection — Claude Code skill
dotnet-csharp-dependency-injection guides Microsoft DI in .NET, from service lifetimes and keyed registrations to decoration and hosted workers.
no license 125 installs ★ 92 updated 2026-02-27
npx skills add wshaddix/dotnet-skills --skill dotnet-csharp-dependency-injection -a claude-codeWhat dotnet-csharp-dependency-injection does
This skill covers common and advanced Microsoft.Extensions.DependencyInjection patterns. It explains how to choose transient, scoped, or singleton lifetimes, connect interfaces to implementations, register multiple implementations, and build factory-based registrations. It also addresses TryAdd, scope checks, and hosted services.
For projects targeting net8.0+, the skill shows keyed service registration and lookup. Its worker examples use BackgroundService with IServiceScopeFactory so a background loop can resolve scoped work inside a fresh scope. Since the built-in container has no native decoration support, the material uses manual wrappers or Scrutor for that case.
Keyed services require net8.0+; older target frameworks need a factory pattern or a dictionary-based design. Check this constraint before choosing keyed registration.
What it helps with
- choose a suitable .NET service lifetime
- spot a scoped dependency captured by a singleton
- register several implementations of one interface
- resolve a service by key on
net8.0+ - run scoped processing from a hosted worker
Example prompts for the agent
- Review this .NET project’s DI setup and find lifetime mismatches.
- Rewrite these named cache registrations with keyed services for
net8.0+. - Create a
BackgroundServicethat resolvesIQueueProcessorthroughIServiceScopeFactory.
How to install dotnet-csharp-dependency-injection
1Skills CLI (Vercel)
npx skills add wshaddix/dotnet-skills --skill dotnet-csharp-dependency-injection -a claude-code2Manually: put the files in place
~/.claude/skills/dotnet-csharp-dependency-injection/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/dotnet-csharp-dependency-injection/
1Skills CLI (Vercel)
npx skills add wshaddix/dotnet-skills --skill dotnet-csharp-dependency-injection -a codex2Manually: put the files in place
.agents/skills/dotnet-csharp-dependency-injection/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add wshaddix/dotnet-skills --skill dotnet-csharp-dependency-injection -a cursor2Manually: put the files in place
.cursor/skills/dotnet-csharp-dependency-injection/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install wshaddix/dotnet-skills skills/dotnet-csharp-dependency-injection2Manually: put the files in place
.github/skills/dotnet-csharp-dependency-injection/SKILL.md1Skills CLI (Vercel)
npx skills add wshaddix/dotnet-skills --skill dotnet-csharp-dependency-injection -a gemini-cli2Platform CLI
gemini skills install https://github.com/wshaddix/dotnet-skills --path skills/dotnet-csharp-dependency-injectionManually: put the files in place
.devin/skills/dotnet-csharp-dependency-injection/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add wshaddix/dotnet-skills --skill dotnet-csharp-dependency-injection -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about dotnet-csharp-dependency-injection
How do I install dotnet-csharp-dependency-injection in Claude Code?
Run npx skills add wshaddix/dotnet-skills --skill dotnet-csharp-dependency-injection -a claude-code, then inspect ~/.claude/skills/dotnet-csharp-dependency-injection/SKILL.md.
What does dotnet-csharp-dependency-injection do?
It guides .NET dependency injection with Microsoft.Extensions.DependencyInjection, covering lifetimes, keyed services, factories, decoration, and hosted services.
Which .NET versions support the keyed service examples?
The keyed service approach requires net8.0+. Earlier target frameworks need a factory pattern or a dictionary-based alternative.