Skip to content
aaronontheweb avatar

Dependency Injection Patterns

Organize service registrations into composable IServiceCollection Add* extension methods for clean Program.cs files.

CCM score
65 of 100
skills.sh installs
732
GitHub stars
1.3K
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers grouping related registrations into feature-level methods, layered composition, and Akka.Hosting actor configuration
  • Includes naming conventions (Add{Feature}Services(), Configure{Feature}(), Use{Feature}()), file placement, and lifetime guidance for singleton, scoped, and transient services
  • Enforces accepting configuration explicitly rather than hiding connection strings or settings inside extension methods
  • Designed for ASP.NET Core teams whose Program.cs has grown unmanageable and who want production registrations reused in tests

Install

$ npx -y skills add aaronontheweb/dotnet-skills --skill dependency-injection-patterns -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

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

Reference Files

  • advanced-patterns.md: Testing with DI extensions, Akka.NET actor scope management, conditional/factory/keyed registration patterns

The Problem

Without organization, Program.cs becomes unmanageable:

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

builder.Services.AddScoped<IUserRepository, UserRepository>();
builder.Services.AddScoped<IOrderRepository, OrderRepository>();
builder.Services.AddScoped<IProductRepository, ProductRepository>();
builder.Services.AddScoped<IUserService, UserService>();
// ... 150 more lines ...

Problems: hard to find related registrations, no clear boundaries, can't reuse in tests, merge conflicts.


The Solution: Extension Method Composition

Details

Repository
github.com/aaronontheweb/dotnet-skills
Categories
.NET & C#, Backend & APIs
First seen
Jun 3, 2026

Questions

What does the dependency-injection-patterns skill do?

The dependency-injection-patterns skill organizes DI registrations using IServiceCollection extension methods. It groups related services into composable Add* methods so Program.cs stays clean and the same configuration can be reused in tests.

How do I install the dependency-injection-patterns skill?

Run npx -y skills add aaronontheweb/dotnet-skills --skill dependency-injection-patterns -y in a project to install it. Once installed, the dependency-injection-patterns skill lets the agent group registrations into Add* methods for ASP.NET Core applications.

Where does dependency-injection-patterns rank in the .NET & C# category?

The dependency-injection-patterns skill ranks in the top 100 of the .NET & C# category on Claude Marketplaces. Other skills in that category include dotnet-backend-patterns, dotnet-best-practices and nuget-manager, and dependency-injection-patterns is the skill to reach for when service registration is the problem.

When should I use the dependency-injection-patterns skill?

Use dependency-injection-patterns when service registrations in an ASP.NET Core application grow into a massive Program.cs or Startup.cs file. It also helps when you want service configuration reused between production and tests, or when designing libraries that integrate with Microsoft.Extensions.DependencyInjection.

More from aaronontheweb/dotnet-skills

All 34

Similar to Dependency Injection Patterns

More .NET & C#