Skip to main content
skill CX Codex

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

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add wshaddix/dotnet-skills --skill dotnet-csharp-dependency-injection -a claude-code
Open on GitHub

What 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 BackgroundService that resolves IQueueProcessor through IServiceScopeFactory.

How to install dotnet-csharp-dependency-injection

1Skills CLI (Vercel)

npx skills add wshaddix/dotnet-skills --skill dotnet-csharp-dependency-injection -a claude-code

2Manually: put the files in place

~/.claude/skills/dotnet-csharp-dependency-injection/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/dotnet-csharp-dependency-injection/

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.

Similar skills

All skills for Backend and APIs →

From the same set24

The whole set →
dotnet-security-owasp dotnet-security-owasp flags OWASP Top 10 vulnerabilities in .NET solutions and guides safe coding. Useful for reviewing ASP.NET Core endpoints and data queries. CX Codex +1 175installs dotnet-api-security dotnet-api-security is a Claude Code skill that handles authentication and authorization in ASP.NET Core APIs. CX Codex +1 169installs dotnet-csharp-async-patterns dotnet-csharp-async-patterns teaches AI agents proper C# async patterns, stopping common blunders like .Result deadlocks, unhandled fire-and-forget tasks, and dropped cancellation tokens. CX Codex +1 136installs dotnet-architecture-patterns dotnet-architecture-patterns guides scalable .NET Minimal API architecture using vertical slices, route groups, endpoint filters, and structured error handling. CX Codex +1 125installs bootstrap5-ui bootstrap5-ui provides Bootstrap 5.3 layout patterns and component snippets for HTML and ASP.NET Core Razor views. CX Codex +1 122installs dotnet-performance-patterns dotnet-performance-patterns is a Claude Code skill for .NET 8+ architecture patterns that reduce allocations using Span, Memory, and ArrayPool. CX Codex +1 122installs Razor Pages Patterns The Razor Pages Patterns skill gives the agent a fixed set of rules for ASP.NET Core Razor Pages: page layout, PageModel design, binding and validation, form security. Fits projects on .NET 8+ with Razor Pages as the UI. CX Codex +1 121installs dotnet-solid-principles dotnet-solid-principles — a skill for Claude Code that applies SOLID, DRY, and SRP principles in .NET projects. Detects C# anti-patterns and suggests specific refactoring steps. CX Codex +1 112installs

Project sponsors

Companies that keep this analytics open