wshaddix avatar

Microsoft Extensions Dependency Injection

Shows you how to organize Microsoft.Extensions.DependencyInjection registrations so your Program.cs doesn't turn into a 200-line mess. The pattern is simple: group related services into extension methods like AddUserServices() or AddEmailServices(), keep them near the code they register, and compose them at startup. The real win is testing. When your production config is a set of composable methods, your WebApplicationFactory tests can call the same AddOrderServices() that production uses and only swap out the email sender or payment processor. Covers naming conventions, file organization, and handling configuration binding. If you've ever had merge conflicts in Startup.cs or copied service registrations into test fixtures, this solves that.

skills.sh installs
552
GitHub stars
90
last updated
Aug 21, 2026

Install

$ npx -y skills add wshaddix/dotnet-skills --skill microsoft-extensions-dependency-injection --agent claude-code

Installs into .claude/skills of the current project.

Files

Dependency Injection Patterns

When to Use This Skill

Use this skill when:

  • Organizing service registrations in ASP.NET Core applications
  • Avoiding massive Program.cs/Startup.cs files with hundreds of registrations
  • Making service configuration reusable between production and tests
  • Designing libraries that integrate with Microsoft.Extensions.DependencyInjection

The Problem

Without organization, Program.cs becomes unmanageable:

// BAD: 200+ lines of unorganized registrations
var builder = WebApplication.CreateBuilder(args);

Sponsors

Details

Repository
github.com/wshaddix/dotnet-skills
Category
.NET & C#
First seen
Jun 3, 2026

More from wshaddix/dotnet-skills

All 13

Recommended

More .NET & C#
1wshaddix avatarserializationwshaddix/dotnet-skillsJSON and binary serialization patterns for .NET applications, including System.Text.Json source generators, Protocol Buffers, MessagePack, and AOT-compatible be530skills.sh installs
2wshaddix avatarmicrosoft-extensions-configurationwshaddix/dotnet-skillsConfiguration patterns using Microsoft.Extensions.Configuration. Covers configuration providers, binding, validation, and best practices for .NET applications. 528skills.sh installs
3aaronontheweb avatarsnapshot-testingaaronontheweb/dotnet-skillsUse Verify for snapshot testing in .NET. Approve API surfaces, HTTP responses, rendered emails, and serialized outputs. Detect unintended changes through human-484skills.sh installs
4aaronontheweb avatarmailpit-integrationaaronontheweb/dotnet-skillsTest email sending locally using Mailpit with .NET Aspire. Captures all outgoing emails without sending them. View rendered HTML, inspect headers, and verify de443skills.sh installs
5aaronontheweb avatarOpenTelemetry-NET-Instrumentationaaronontheweb/dotnet-skillsProvides guidance for implementing OpenTelemetry instrumentation in .NET codebases, covering tracing (Activities/Spans), metrics, logs, naming conventions, erro431skills.sh installs
6aaronontheweb avatarakka-net-aspire-configurationaaronontheweb/dotnet-skillsConfigure Akka.NET with .NET Aspire for local development and production deployments. Covers actor system setup, clustering, persistence, Akka.Management integr415skills.sh installs