All skills
Skillintermediate

C# Patterns

> This file extends [common/patterns.md](../common/patterns.md) with C#-specific content.

Claude Code Knowledge Pack7/10/2026

Overview

C# Patterns

This file extends common/patterns.md with C#-specific content.

API Response Pattern

public sealed record ApiResponse(
    bool Success,
    T? Data = default,
    string? Error = null,
    object? Meta = null);

Repository Pattern

public interface IRepository
{
    Task<IReadOnlyList> FindAllAsync(CancellationToken cancellationToken);
    Task<T?> FindByIdAsync(Guid id, CancellationToken cancellationToken);
    Task CreateAsync(T entity, CancellationToken cancellationToken);
    Task UpdateAsync(T entity, CancellationToken cancellationToken);
    Task DeleteAsync(Guid id, CancellationToken cancellationToken);
}

Options Pattern

Use strongly typed options for config instead of reading raw strings throughout the codebase.

public sealed class PaymentsOptions
{
    public const string SectionName = "Payments";
    public required string BaseUrl { get; init; }
    public required string ApiKeySecretName { get; init; }
}

Dependency Injection

  • Depend on interfaces at service boundaries
  • Keep constructors focused; if a service needs too many dependencies, split responsibilities
  • Register lifetimes intentionally: singleton for stateless/shared services, scoped for request data, transient for lightweight pure workers