microsoft-extensions-dependency-injection

Organize .NET dependency injection registrations into reusable Add* extension methods.

3|Updated Jan 24, 2024
One-click install
npx skills add https://github.com/akoken/dotfiles --skill microsoft-extensions-dependency-injection
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: microsoft-extensions-dependency-injection
Source: https://github.com/akoken/dotfiles/tree/main/config/.copilot/skills/microsoft-extensions-dependency-injection
Command: npx skills add https://github.com/akoken/dotfiles --skill microsoft-extensions-dependency-injection

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps teams organize and reuse dependency injection configuration by encapsulating registrations into composable Add* extension methods, keeping Program.cs clean and making tests easier to configure.

Core Features & Use Cases

  • Group related registrations into cohesive extension methods like AddUserServices, AddOrderServices, and AddEmailServices.
  • Enable layered service composition across Domain, Infrastructure, and API boundaries for easier maintenance and testing.
  • Support testing via reuse of production registrations and targeted overrides in WebApplicationFactory or Akka.Hosting tests.

Quick Start

Example: register a feature by calling services.AddUserServices() in Program.cs, then override test dependencies as needed in tests.

Frequently Asked Questions about microsoft-extensions-dependency-injection

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 keep Program.cs clean?

Organize dependency injection registrations in ASP.NET Core by grouping related services into reusable Add* extension methods like AddUserServices. This encapsulates registrations into composable layers, keeping Program.cs clean and making configurations easier to maintain.

How do I reuse production DI configurations for testing in .NET?

Reuse production DI configurations for testing by calling your Add* extension methods within WebApplicationFactory or Akka.Hosting test setups. You can apply production registrations and then apply targeted overrides for specific test dependencies.

What's the best way to structure layered service composition across Domain, Infrastructure, and API boundaries?

Structure layered service composition by encapsulating related dependencies into cohesive Add* extension methods. This pattern separates Domain, Infrastructure, and API registrations, enabling easier maintenance and testing across application boundaries.

Can I use extension methods for dependency injection with Akka.Hosting scenarios?

Yes, you can use extension methods for dependency injection with Akka.Hosting scenarios. This approach supports testing-friendly configuration by allowing you to reuse production registrations and override dependencies as needed during Akka.Hosting tests.

Does this dependency injection pattern support configuration binding in ASP.NET Core?

Yes, this dependency injection pattern supports configuration binding in ASP.NET Core. You can encapsulate configuration binding logic within your reusable Add* extension methods alongside your service registrations.