dependency-injection

Resolve incorrect .NET dependency injection lifetimes and registration patterns.

1|Updated Apr 28, 2026
One-click install
npx skills add https://github.com/Trossitec/dotnet-claude-kit --skill dependency-injection-trossitec
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dependency-injection
Source: https://github.com/Trossitec/dotnet-claude-kit/tree/main/skills/dependency-injection
Command: npx skills add https://github.com/Trossitec/dotnet-claude-kit --skill dependency-injection-trossitec

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Dependency injection failures in .NET cause runtime bugs, memory leaks, and brittle service composition when lifetimes are mismatched or when the wrong registration strategy is used.

Core Features & Use Cases

  • Lifetime-safe service registration: Prevents singleton/scoped capture issues and enforces correct lifetime choices for DbContext and other dependencies.
  • Modern DI patterns: Applies keyed services for strategy routing, decorator wrapping for cross-cutting concerns, and factory delegates for runtime selection.
  • Convention-based wiring: Uses Scrutor-style registration-by-convention to reduce boilerplate and keep interfaces aligned with implementations.
  • Options binding for typed configuration: Loads configuration into strongly typed options with validation for predictable runtime behavior.

Quick Start

Load the dependency-injection skill when you register services or debug DI errors by asking: "Show me the correct lifetimes and registration pattern for my IServiceCollection setup, and refactor it to use keyed services or decorators where appropriate."

Frequently Asked Questions about dependency-injection

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

FAQPage Schema
How do I fix scoped service lifetime issues in .NET dependency injection?

Resolve scoped service lifetime issues in .NET dependency injection by enforcing correct lifetime rules, preventing singleton captures of scoped dependencies, and applying proper service registration patterns to avoid runtime bugs and memory leaks.

What is the best way to register .NET services by convention to reduce boilerplate?

Register .NET services by convention using Scrutor-style registration to automatically align interfaces with implementations, reducing manual boilerplate and ensuring consistent dependency injection wiring across your application.

How do I use keyed services for strategy routing in .NET dependency injection?

Use keyed services in .NET dependency injection for strategy routing by selecting specific implementations at runtime, allowing you to dynamically resolve the correct service variant based on your application's contextual needs.

How do I apply the decorator pattern with .NET dependency injection for cross-cutting concerns?

Apply the decorator pattern in .NET dependency injection to wrap existing services and compose cross-cutting behaviors, ensuring concerns like logging or caching are handled cleanly without modifying core implementations.

How do I bind strongly typed configuration options in .NET with validation?

Bind strongly typed configuration options in .NET by loading configuration into typed objects with validation, ensuring predictable runtime behavior and catching invalid configuration settings during application startup.

Why does my .NET dependency injection setup cause memory leaks and brittle service composition?

Your .NET dependency injection setup causes memory leaks and brittle composition when lifetimes are mismatched or the wrong registration strategy is used, which requires applying correct lifetime rules and anti-pattern detection.