.claude/skills/gen-factory-class/SKILL.md
Use when creating a static factory for a strategy or provider pattern in a black-box library (no DI container). Generates a thread-safe cached static factory dispatching by enum key with typed convenience methods. Also invoke when the user mentions: static factory, provider factory, enum-keyed factory, library factory pattern. Domain: Code Generation, Design Patterns. Level: Intermediate.
npx skillsauth add klod68/littlerae gen-factory-classInstall 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 cached static factory for creating ${1:IInterfaceName} implementations
dispatched by ${2:EnumName}.
${3:MyApp}${4:Value1 → Impl1Class, Value2 → Impl2Class, Value3 → Impl3Class}${3}.Factories.${1/^I//}Factory.cs
/// <summary>
/// Thread-safe cached factory for <see cref="${1}"/> implementations.
/// </summary>
public static class ${1/^I//}Factory
{
private static readonly ConcurrentDictionary<${2}, ${1}> s_cache = new();
/// <summary>
/// Returns a cached <see cref="${1}"/> for the specified <paramref name="type"/>.
/// </summary>
/// <param name="type">The implementation type to create or retrieve.</param>
/// <returns>A cached <see cref="${1}"/> instance.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when <paramref name="type"/> has no registered implementation.
/// </exception>
public static ${1} Create(${2} type)
=> s_cache.GetOrAdd(type, static key => key switch
{
// one case per enum value — filled from context above
_ => throw new ArgumentOutOfRangeException(
nameof(type), type, $"No implementation registered for {nameof(${2})}.{type}.")
});
// Typed convenience methods — one per enum value
}
${3}.Instances.{Domain}/{ImplN}Class.cs ← one file per implementation
internal sealed class {ImplN} : ${1}${3}.Domain.${2}.cs
public static — it is the only public entry point for instancesinternal sealed — never publicConcurrentDictionary.GetOrAdd with a static lambda for thread-safe allocation-free cachingswitch expression (not if-else) for exhaustive enum dispatchArgumentOutOfRangeException for unknown values — never NotImplementedException${1} (the interface) — never a concrete typeCreateValue1(), CreateValue2()) wrap the main Create methodCreate method, and every convenience 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.