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
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 -yInstalls 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- Database Performance731
- Dotnet Project Structure723
- Type Design Performance716
- Api Design715
- Ilspy Decompile684
- Microsoft Extensions Configuration636
- Package Management635
- Serialization622
- Testcontainers Integration Tests615
- Dotnet Slopwatch611
- Crap Analysis605
- Playwright Blazor Testing582
- Dotnet Local Tools573
- Aspire Integration Testing545
- Mjml Email Templates535
- Aspire Service Defaults520
- Snapshot Testing509
- Aspire Configuration508
- Dotnet Devcert Trust480
- Skills Index Snippets478
- Playwright Ci Caching476
- Akka Net Best Practices472
- Mailpit Integration465
- Verify Email Snapshots458
Similar to Dependency Injection Patterns
More .NET & C#microsoft-extensions-dependency-injectionwshaddix/dotnet-skills557 installsExtension-method composition for grouping .NET DI registrations, with production configuration reusable in tests.
microsoft-extensions-configurationaaronontheweb/dotnet-skills636 installsStrongly-typed .NET configuration with Options pattern validation enforced at application startup.
aspire-configurationaaronontheweb/dotnet-skills508 installsExplicit AppHost-to-app configuration bridge that keeps Aspire client and service-discovery packages out of app code.
maui-dependency-injectiondotnet/skills4.6K installsGuidance for configuring dependency injection in .NET MAUI apps, from service registration to lifetime selection.
dotnet-patternsaffaan-m/ecc10.9K installsIdiomatic C# and .NET conventions covering immutability, dependency injection, async/await, and common application patterns.
dotnet-backend-patternswshobson/agents20K installsMaster C#/.NET patterns for production APIs covering async, DI, EF Core, Dapper, caching, and testing.