dependency-injection

Manage dependency injection lifetimes and service registrations in .NET projects.

640|145|Updated Feb 20, 2026
One-click install
npx skills add https://github.com/codewithmukesh/dotnet-claude-kit --skill dependency-injection-codewithmukesh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dependency-injection
Source: https://github.com/codewithmukesh/dotnet-claude-kit/tree/main/skills/dependency-injection
Command: npx skills add https://github.com/codewithmukesh/dotnet-claude-kit --skill dependency-injection-codewithmukesh

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Dependency injection misconfigurations cause subtle runtime bugs, memory leaks, and incorrect behavior when service lifetimes are mismatched or registrations are inconsistent. This Skill helps you reason about service lifetimes, avoid captive dependencies, and choose the right patterns for composition and resolution in modern .NET projects.

Core Features & Use Cases

  • Lifetime guidance: Clear rules to match singleton, scoped, and transient lifetimes and avoid capturing scoped services in singletons.
  • Patterns and resolution: Recommendations and examples for keyed services, decorator pattern, factory delegates, and convention-based registration using Scrutor.
  • Configuration and options: Best practices for registering strongly-typed configuration, validating on start, and injecting options safely.
  • Use case: When reviewing service registrations in a .NET 10 application, it helps identify lifetime mismatches, propose decorator wiring for cross-cutting concerns, and convert factory logic to keyed services where appropriate.

Quick Start

Ask the skill to analyze your service registrations, fix lifetime mismatches, and recommend keyed services, decorators, or convention-based registrations.

Frequently Asked Questions about dependency-injection

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

FAQPage Schema
How do I fix dependency injection lifetime mismatches in .NET?

Fix dependency injection lifetime mismatches by ensuring singleton, scoped, and transient registrations align correctly to avoid captive dependencies. Validating service registrations on start prevents memory leaks and subtle runtime bugs in .NET applications.

What is a captive dependency in .NET dependency injection?

A captive dependency occurs when a singleton service captures a scoped service, causing the scoped service to live longer than intended. Avoiding captive dependencies ensures correct lifetime matching and prevents unexpected behavior in .NET applications.

How do I register decorators using Scrutor in .NET?

Register decorators using Scrutor by applying convention-based scanning to wire cross-cutting concerns around existing service registrations. This pattern streamlines service composition without modifying the original implementation logic in .NET codebases.

Does .NET 10 support keyed services for dependency injection?

Yes, .NET 10 supports keyed services for dependency injection, allowing you to resolve service implementations by a specific key. This feature helps replace complex factory delegates with direct, streamlined service resolution logic.

When should I use a factory delegate versus keyed services in .NET?

Use keyed services instead of factory delegates when you need to resolve specific service implementations by key in .NET. Keyed services streamline registration and resolution, replacing complex factory wiring with direct, declarative service composition.

Can I validate .NET dependency injection registrations on application start?

Yes, you can validate .NET dependency injection registrations on application start to detect lifetime mismatches early. This ensures strongly-typed configuration and options are injected safely before runtime execution begins.