dependency-injection

Design and correct .NET dependency injection registrations for lifetime safety.

1|Updated Mar 27, 2026
One-click install
npx skills add https://github.com/Maj3D10/Training-Platform --skill dependency-injection-maj3d10
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dependency-injection
Source: https://github.com/Maj3D10/Training-Platform/tree/main/.agent/skills/dependency-injection
Command: npx skills add https://github.com/Maj3D10/Training-Platform --skill dependency-injection-maj3d10

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you design and troubleshoot .NET dependency injection by preventing lifetime bugs and choosing the right registration patterns for complex service graphs.

Core Features & Use Cases

  • Service lifetime correctness: Identify and avoid invalid singleton/scoped/transient dependencies that cause stale data, memory leaks, or runtime failures.
  • Strategy and runtime selection: Use keyed services to select implementations safely instead of ad-hoc factory logic.
  • Compositional design: Apply decorators, Scrutor convention-based registration, and delegate factories to build maintainable service layers.
  • Options binding: Register and inject strongly-typed configuration using AddOptions<T>() with validation.

Quick Start

Load the dependency-injection skill when you are registering services in .NET and want guidance on resolving lifetime issues or implementing keyed services and decorators.

Frequently Asked Questions about dependency-injection

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

FAQPage Schema
How do I fix .NET dependency injection lifetime bugs causing runtime failures?

Fix .NET dependency injection lifetime bugs by validating singleton, scoped, and transient service wiring to prevent invalid dependencies, stale data, and memory leaks. This Skill corrects IServiceCollection registrations to ensure lifetime-safe composition.

When should I use keyed services instead of factory pattern for .NET dependency injection?

Use keyed services for .NET dependency injection when you need to safely select specific implementations at runtime. Keyed services provide structured resolution, replacing ad-hoc factory logic and ensuring correct service composition.

How do I apply the decorator pattern with Scrutor convention-based registration in .NET?

Apply the decorator pattern in .NET using Scrutor convention-based registration to compose cross-cutting behavior and build maintainable service layers. This Skill guides decorator implementation to correctly wrap IServiceCollection registrations.

Can I use AddOptions<T>() with validation for strongly-typed configuration in .NET dependency injection?

Yes, you can use AddOptions<T>() with validation to register and inject strongly-typed configuration in .NET dependency injection. This ensures configuration binding is validated during IServiceCollection setup before service resolution.

Why does my .NET dependency injection captive dependency cause stale data and memory leaks?

A .NET dependency injection captive dependency causes stale data and memory leaks when a singleton service incorrectly traps a scoped or transient dependency. This Skill identifies invalid singleton, scoped, and transient wiring to prevent these runtime failures.