dependency-injection-patterns

Organize ASP.NET Core dependency injection registrations into feature-specific Add* extension methods.

Updated May 4, 2026
One-click install
npx skills add https://github.com/clarivex-tech/pervaxis-forge --skill dependency-injection-patterns-clarivex-tech
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dependency-injection-patterns
Source: https://github.com/clarivex-tech/pervaxis-forge/tree/main/pervaxis-forge-api/.claude/skills/microsoft-extensions-dependency-injection
Command: npx skills add https://github.com/clarivex-tech/pervaxis-forge --skill dependency-injection-patterns-clarivex-tech

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Organize ASP.NET Core dependency injection registrations by grouping related services into feature-specific Add* extension methods, reducing oversized Program.cs files and enabling test-time reuse.

Core Features & Use Cases

  • Group related services into feature-specific extension methods (e.g., AddUserServices, AddOrderServices).
  • Compose registrations hierarchically near services (File Organization) and enable testing reuse.
  • Support advanced patterns like keyed services, options configuration, and DI testing patterns.

Quick Start

Create modular Add* extension methods for each feature and call them in Program.cs to compose 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 in a large ASP.NET Core project?

Organize dependency injection registrations by grouping related services into feature-specific Add* extension methods, reducing oversized Program.cs files and enabling test-time composition. Call these modular extensions hierarchically to compose your application's service collection.

What is the best way to modularize ASP.NET Core service collections for testing?

Modularize ASP.NET Core service collections by creating feature-based Add* extension methods that encapsulate service registrations. This pattern enables test-time reuse by allowing tests to compose only the specific feature services needed without loading the entire application's dependency graph.

Does this dependency injection pattern support keyed services and options configuration?

Yes, this dependency injection pattern supports advanced ASP.NET Core features including keyed services and options configuration. The extension method approach accommodates these modern Microsoft.Extensions.DependencyInjection capabilities within feature-specific registration groups.

Can I use feature-based Add* extension methods with Microsoft.Extensions.DependencyInjection?

Yes, feature-based Add* extension methods work directly with Microsoft.Extensions.DependencyInjection. You create static extension classes that wrap IServiceCollection registration calls, then invoke them in Program.cs to compose modular dependency injection blocks.

When should I split dependency injection registrations into separate extension methods?

Split dependency injection registrations into separate extension methods when managing large ASP.NET Core codebases seeking reusable production configurations. This approach is ideal when Program.cs becomes oversized or when multiple test projects need to compose specific feature services independently.