dependency-injection-patterns

Organize Microsoft.Extensions.DependencyInjection registrations into reusable Add*Services() extension methods.

Updated Mar 3, 2026
One-click install
npx skills add https://github.com/Thorstensen/claude-template --skill dependency-injection-patterns-thorstensen
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dependency-injection-patterns
Source: https://github.com/Thorstensen/claude-template/tree/main/.claude/skills/microsoft-extensions-dependency-injection
Command: npx skills add https://github.com/Thorstensen/claude-template --skill dependency-injection-patterns-thorstensen

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Organizing Microsoft.Extensions.DependencyInjection registrations in large ASP.NET Core projects becomes unwieldy, leading to bloated program startup and duplicated wiring across features.

Core Features & Use Cases

  • Extension-method-based grouping of registrations into Add*Services() methods, enabling clean composition of feature registrations.
  • Reusable, test-friendly configuration that can be shared between production code and tests without duplicating setup.
  • Clear guidelines for naming, layering extensions, and integrating with options/configuration and Akka.Hosting patterns.

Quick Start

Create an AddUserServices extension to bundle user-related registrations and call it from Program.cs.

Frequently Asked Questions about dependency-injection-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I organize dependency injection registrations in ASP.NET Core to avoid bloated Program.cs startup files?

You can organize dependency injection registrations by grouping related services into reusable Add*Services() extension methods. This pattern cleans up Program.cs startup and prevents duplicated wiring across features in large ASP.NET Core projects.

What is the best way to share dependency injection setup between production code and test environments?

The best way to share dependency injection setup is creating test-friendly extension methods. Reusable Add*Services() methods allow consistent DI wiring across production and test environments without duplicating configuration setup.

How do I layer extension methods for dependency injection when integrating options and configuration patterns?

You layer dependency injection extensions by building composite Add*Services() methods that call granular feature extensions. This approach integrates cleanly with options/configuration patterns and provides clear guidelines for layered extension composition.

Can I use this dependency injection extension method pattern with Akka.Hosting in ASP.NET Core?

Yes, the dependency injection extension method pattern integrates with Akka.Hosting in ASP.NET Core. The approach provides clear guidelines for organizing service collection registrations alongside Akka.Hosting patterns for consistent wiring.

When do I need to group service collection registrations into extension methods instead of inline calls?

You need to group service collection registrations when your ASP.NET Core project experiences unwieldy startup or duplicated wiring. Grouping into extension methods enables clean composition of feature registrations and testable configuration.