.claude/skills/criteria-pattern/SKILL.md
Use when a search, filter, or query method has more than 2–3 optional parameters and the parameter list keeps growing, or when adding a new filter requires changing method signatures across multiple call sites. Covers the typed criteria object pattern (e.g., ProductCriteria), conditional LINQ filtering, paged variants with IPagedRequest, and naming conventions for ByCriteria, ById, and Paged overloads. Domain: Architecture, Query Design. Level: Foundational. Tags: criteria, query, filtering, search, specification.
npx skillsauth add klod68/littlerae criteria-patternInstall 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.
Methods with growing parameter lists for filtering (e.g., GetProducts(string? name, decimal? minPrice, decimal? maxPrice, string? category, bool? isActive)) become unwieldy. Adding a filter requires changing the method signature everywhere.
Encapsulate filter parameters in a typed criteria object. The method accepts one TCriteria parameter instead of N optional parameters. Adding a filter means adding a property — no signature changes anywhere.
public sealed class ProductCriteria
{
public string? NameSearch { get; set; }
public string? Category { get; set; }
public decimal? MinPrice { get; set; }
public decimal? MaxPrice { get; set; }
public bool? IsActive { get; set; }
}
public interface IProductService
{
Task<IReadOnlyList<Product>> GetProductsAsync(
ProductCriteria criteria,
CancellationToken ct = default);
}
public async Task<IReadOnlyList<Product>> GetProductsAsync(
ProductCriteria criteria,
CancellationToken ct = default)
{
ArgumentNullException.ThrowIfNull(criteria);
var query = _products.AsQueryable();
if (!string.IsNullOrWhiteSpace(criteria.NameSearch))
query = query.Where(p => p.Name.Contains(criteria.NameSearch, StringComparison.OrdinalIgnoreCase));
if (!string.IsNullOrWhiteSpace(criteria.Category))
query = query.Where(p => p.Category == criteria.Category);
if (criteria.MinPrice.HasValue)
query = query.Where(p => p.Price >= criteria.MinPrice.Value);
if (criteria.MaxPrice.HasValue)
query = query.Where(p => p.Price <= criteria.MaxPrice.Value);
if (criteria.IsActive.HasValue)
query = query.Where(p => p.IsActive == criteria.IsActive.Value);
return query.ToList();
}
| Variant | Purpose | Example |
|---------|---------|---------|
| *ByCriteria | Filter by multiple fields | GetProductsByCriteriaAsync(ProductCriteria) |
| *ById | Filter by primary key | GetProductByIdAsync(int id) |
| *Paged | Criteria + pagination | GetProductsPagedAsync(ProductCriteria, IPagedRequest) |
public interface IProductService
{
Task<IReadOnlyList<Product>> GetProductsByCriteriaAsync(ProductCriteria criteria, CancellationToken ct = default);
Task<Product?> GetProductByIdAsync(int id, CancellationToken ct = default);
Task<IPagedResult<Product>> GetProductsPagedAsync(ProductCriteria criteria, IPagedRequest paging, CancellationToken ct = default);
}
GetById) — a simple parameter is clearernull or unset property means "don't filter on this field."{Entity}Criteria for consistency across the codebase.ArgumentNullException.ThrowIfNull(criteria) — the criteria object itself must not be null.AsNoTracking() for read-only queries in EF Core.tools
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.