extensions-review

Guides implementation of Microsoft.Extensions and System.IO.Compression code in dotnet/runtime.

18.2k|5.6k|Updated Sep 24, 2019
One-click install
npx skills add https://github.com/dotnet/runtime --skill extensions-review
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: extensions-review
Source: https://github.com/dotnet/runtime/tree/main/.github/skills/extensions-review
Command: npx skills add https://github.com/dotnet/runtime --skill extensions-review

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing code for Microsoft.Extensions.* and System.IO.Compression libraries involves subtle pitfalls like captive dependencies, incorrect DI lifetimes, blocking async compression, and trim/AOT incompatibilities that are easy to miss without deep framework knowledge.

Core Features & Use Cases

  • DI Lifetime Guidance: Decision trees for choosing Singleton, Scoped, or Transient lifetimes and avoiding captive dependencies with IServiceScopeFactory.
  • Configuration, Options & Logging Patterns: Covers configuration binding with validation, IValidateOptions implementations, and high-performance logging via the [LoggerMessage] source generator.
  • Compression & Caching Guidance: Proper async compression with BrotliStream, ZipArchive extraction preserving Unix permissions, and stampede-safe caching with HybridCache.
  • Use Case: When adding a new hosted service to dotnet/runtime, use this Skill to implement a safe BackgroundService with graceful shutdown, register it with TryAdd patterns, and verify trim/AOT safety before submitting.

Quick Start

Ask the AI to review or write Microsoft.Extensions dependency injection code following the extensions-review guidance for dotnet/runtime.

Frequently Asked Questions about extensions-review

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

FAQPage Schema
How do I choose between Singleton, Scoped, and Transient in .NET dependency injection?

Choose Singleton for stateless or immutable services, Scoped for state tied to a logical operation like a request, and Transient when a fresh instance is needed each time. Never inject a Scoped service into a Singleton, as that creates a captive dependency; use IServiceScopeFactory instead.

How do I avoid captive dependencies in .NET DI?

Avoid injecting scoped services directly into singletons. Instead, inject IServiceScopeFactory into the singleton, create an async scope on demand with CreateAsyncScope, and resolve the scoped service within that scope's lifetime.

Does configuration binding work with AOT-published .NET apps?

Runtime configuration binding uses reflection and is not trim or AOT safe. For trimmed or AOT-published apps, use source-generated configuration binding and verify parity with the runtime binder for all bound types.

What is the fastest way to log in high-frequency .NET code paths?

Use the [LoggerMessage] source generator for high-frequency log sites, as it provides zero-allocation logging. For infrequent logging, standard ILogger.Log{Level} calls with message templates are acceptable.

Why does my async compression method block the thread?

Blocking happens when synchronous work like reading all bytes runs before the first await. Use truly async APIs from the start, such as copying the input stream into a BrotliStream with CopyToAsync and honoring the cancellation token.

When should I use TryAddSingleton instead of AddSingleton?

Use TryAdd methods for default service registrations in library extension methods. TryAdd only registers the service if no implementation is already registered, letting consumers override defaults without duplicate registrations.