.claude/skills/gen-di-composition-root/SKILL.md
Use when wiring a new application module into the DI container. Generates an IServiceCollection extension method composition root with options validation, safe-copy overload, and convenience helpers. Do NOT use for static black-box libraries — use gen-factory-class instead. Also invoke when the user mentions: DI registration, AddMyModule, composition root, service registration extension. Domain: Code Generation, Dependency Injection. Level: Intermediate.
npx skillsauth add klod68/littlerae gen-di-composition-rootInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Generate a DI composition root for the module: ${1:ModuleName}.
Static library check: if this project is a NuGet-distributed class library with no internal DI container, stop here and use
/gen-factory-classinstead. This prompt applies to: Application, Web App, API, and Module projects only.
${2:MyApp}${3:e.g. EmailSender → IEmailSender → Scoped, EmailQueue → IEmailQueue → Singleton}${4:e.g. ConnectionString string required, TimeoutSeconds int 30, EnableRetry bool true}${2}.${1}.Configuration.I${1}Options.cs
${2}.${1}.Configuration.${1}Options.cs
get; set; properties onlysealed implementation with sensible defaultsEnsureValid() method that throws InvalidOperationException with actionable messages
for every required property and every out-of-range valueappsettings.json snippet showing all keys and defaults${2}.${1}.Configuration.${1}ServiceCollectionExtensions.cs
public static class ${1}ServiceCollectionExtensions
{
// Overload 1: Action<TOptions> — most common consumer pattern
public static IServiceCollection Add${1}(
this IServiceCollection services,
Action<${1}Options> configure)
// Overload 2: pre-built options instance
public static IServiceCollection Add${1}(
this IServiceCollection services,
I${1}Options options)
// Private core — shared logic
private static IServiceCollection Add${1}Core(
IServiceCollection services,
${1}Options options)
}
Inside Add${1}Core:
services.TryAddSingleton<I${1}Options>(options) — register options instanceservices.TryAdd* for each internal service (never overwrite consumer registrations)When accepting I${1}Options, copy all properties into a new ${1}Options instance
before registering. This prevents mutation after registration and avoids trusting
untrusted interface implementations.
ArgumentNullException.ThrowIfNull on both services and configure / optionsEnsureValid() called eagerly — fail at startup, not at first useTryAdd* throughout — never plain Add* (respect consumer registrations)Core method avoids logic duplication between overloadsinternal sealedpublic sealed (it crosses the module boundary)new ConcreteType() for services — DI resolves themIServiceProvider access inside the extension methodtools
Use when cross-cutting concerns (logging, metrics, validation, authorization) are tangled into command handlers or service methods, when building database command pipelines with reorderable concerns, or when HTTP client pipelines or message handlers need composable, independently-replaceable processing stages. Covers ICommandInterceptor interface, InterceptorPipeline with reverse-chain construction, zero-cost Empty sentinel to skip overhead when no interceptors are registered, and ConfigureAwait(false) discipline for library code. Domain: Architecture, Cross-Cutting Concerns. Level: Intermediate. Tags: interceptor, pipeline, middleware, decorator, cross-cutting-concerns.
development
Use when writing integration tests for Razor Pages, MVC, or Minimal API applications to validate routing, middleware, page rendering, and HTTP behavior without a browser or live server, or when adding fast smoke tests to a CI pipeline. Covers WebApplicationFactory<Program> setup with public partial class Program, in-memory test server, AngleSharp HTML parsing, CSS selector assertions, redirect and status code testing, and a shared static fixture pattern for minimal per-test startup overhead. Domain: Testing, ASP.NET Core. Level: Intermediate. Tags: integration-testing, webapplicationfactory, razor-pages, anglesharp, http-testing.
development
Use when designing indexes for new tables, diagnosing slow queries that are not using indexes efficiently, reviewing index fragmentation and maintenance, or when the current indexing strategy results in key lookups, table scans, or missing index warnings. Covers clustered index key selection (narrow, unique, ever-increasing), non-clustered index design for query patterns, covering indexes with INCLUDE columns, filtered indexes for subset queries, composite index column ordering, DMV-based monitoring for missing and unused indexes, and rebuild vs reorganize maintenance thresholds. Domain: Database, Performance. Level: Intermediate. Tags: index, sql-server, covering-index, filtered-index, performance, dmv, maintenance.
development
Use when building a searchable in-memory catalog or registry for documentation sites, admin panels, or type/API browsers where you need keyword matching, fuzzy search, and ranked results without an external search engine or database. Covers RegistryService with weighted scoring across name, description, keywords, and method names; Levenshtein fuzzy matching; synonym expansion; category and subcategory filtering; and singleton DI registration for datasets of hundreds to low thousands of items. Domain: Search, Data Access Patterns. Level: Intermediate. Tags: search, registry, fuzzy-matching, in-memory, catalog, filtering.