dependency-injection-patterns

Organize dependency injection registrations into reusable Add* extension methods.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/tvcosta/ai-customer-service --skill dependency-injection-patterns-tvcosta
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dependency-injection-patterns
Source: https://github.com/tvcosta/ai-customer-service/tree/main/.claude/skills/microsoft-extensions-dependency-injection
Command: npx skills add https://github.com/tvcosta/ai-customer-service --skill dependency-injection-patterns-tvcosta

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Organizes and modularizes dependency injection registrations to avoid sprawling Program.cs and to enable reusable configuration across production and tests.

Core Features & Use Cases

  • Extension Method Composition: group related registrations into cohesive Add* methods.
  • Reuse in tests: compose production DI once and override only test-specific parts.
  • Layered extensions: compose domain, infrastructure, and API registrations hierarchically.

Quick Start

Call AddUserServices() and other Add* extensions during startup to compose DI registrations.

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 to avoid a sprawling Program.cs?

Group related dependency injection registrations into cohesive Add* extension methods that return IServiceCollection. This modular architecture prevents a sprawling Program.cs and enables reusable configuration across both production and test environments.

Can I reuse production DI registrations in unit tests and override only specific parts?

Yes, you can reuse production dependency injection registrations in tests by composing production DI once and overriding only test-specific parts. This test-time DI reuse is enabled through hierarchical composition of Add* extension methods.

What is the best way to layer domain and infrastructure dependency injection in ASP.NET Core?

The best way to layer dependency injection is through hierarchical composition of Add* extension methods. You compose domain, infrastructure, and API registrations hierarchically, allowing configuration-aware options and a modular architecture across services and repositories.

Does this dependency injection pattern support configuration-aware options for library design?

Yes, this dependency injection pattern supports configuration-aware options and is fully applicable to library design. It fulfills functional requirements for extension-based registrations that return IServiceCollection, allowing seamless integration of services and integrations.

When should I not use extension methods for modular architecture in dependency injection?

You should reconsider using extension methods for modular architecture in dependency injection if your application lacks complex service registrations or test-time DI reuse requirements. Simple startup composition may not benefit from the added abstraction of hierarchical Add* extensions.