Agent skill · software engineering · aaronontheweb

dependency-injection-patterns

Organize DI registrations using IServiceCollection extension methods. Group related services into composable Add* methods for clean Program.cs and reusable configuration in tests.

Why this skill is useful

Provides specific patterns for organizing dependency injection in ASP.NET Core that the AI wouldn't reliably generate on its own.

What it needs

About 4k tokens when loaded. Last updated 2026-07-03. 1,095 stars on the source repository.

What this skill does

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: Problems: hard to find related registrations, no clear boundaries, can't reuse in tests, merge conflicts. --- The Solution: Extension Method Composition Group related registrations into extension methods: --- Extension Method Pattern Basic Structure With Configuration --- File Organization Place extension methods near the services they register: Convention: {Feature}ServiceCollectionExtensions.cs next to the feature's services. --- Naming Conventions Pattern Use For --------- --------- Add{Feature}Services() General feature registration Add{Feature}() Short form when unambiguous Configure{Feature}() When primarily setting options Use{Feature}() Middleware (on IApplicationBuilder) --- Testing Benefits The Add pattern lets you reuse production configuration in tests and only override what's different. Works with WebApplicationFactory, Akka.Hosting.TestKit, and standalone ServiceCollection. See advanced-patterns.md for complete testing examples. --- Layered Extensions For larger applications, compose extensions hierarchically: --- Akka.Hosting Integration The same pattern works for Akka.NET actor configuration: See akka-hosting-actor-patterns skill for complete Akka.Hosting patterns. …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills aaronontheweb/microsoft-extensions-dependency-injection

View the source on GitHub

Browse the @skills marketplace