cratis-engineering-csharp-conventions

Apply Cratis C# house conventions for formatting, naming, exceptions, logging, and dependency injection.

3|Updated Dec 25, 2024
One-click install
npx skills add https://github.com/Cratis/Samples --skill cratis-engineering-csharp-conventions-cratis
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: cratis-engineering-csharp-conventions
Source: https://github.com/Cratis/Samples/tree/main/.cratis/ai/skills/cratis-engineering-csharp-conventions
Command: npx skills add https://github.com/Cratis/Samples --skill cratis-engineering-csharp-conventions-cratis

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? C# code written across Cratis repositories drifts in style without a shared reference, leading to inconsistent naming, formatting, exception handling, and dependency injection patterns that slow down reviews and introduce subtle bugs like captive singleton dependencies. ## Core Features & Use Cases - Style Enforcement Guidance: Covers formatting, naming, records, primary constructors, nullable handling, pattern matching, and multiline XML documentation rules. - Exceptions, Logging, and DI Rules: Defines domain exception conventions, structured logging with [LoggerMessage], convention-based DI, and the narrow conditions for using [Singleton]. - Domain Philosophy: Explains CUPID characteristics, cohesion by feature over technical layers, ubiquitous language, and immutability principles. - Use Case: When writing a new command handler in a Cratis repository, consult this Skill to name the type after the domain, use a primary constructor, inject collaborators by convention, and document the public API with multiline XML comments. ## Quick Start Review my C# code against the Cratis engineering conventions and point out any violations in naming, formatting, exceptions, or dependency injection.

Frequently Asked Questions about cratis-engineering-csharp-conventions

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

FAQPage Schema
How do I write C# code that follows Cratis conventions?▼

Use records for events, commands, and DTOs, primary constructors for classes, file-scoped namespaces, var for locals, and is null checks. Name types after the domain without technical postfixes like Service, Manager, or Handler, and document every public member with multiline XML comments.

How should I name custom exceptions in C#?▼

Define a domain exception deriving from Exception without the Exception suffix, such as AuthorNotFound instead of AuthorNotFoundException. Always supply a meaningful message and document it with an XML summary starting with "The exception that is thrown when".

When is it safe to use the [Singleton] attribute in dependency injection?▼

Use [Singleton] only for process-wide services holding no tenant-, user-, or request-bound state. A singleton capturing a scoped collaborator silently binds to the root scope's default namespace forever; inject IServiceScopeFactory and open a scope per unit of work instead.

Should I use IEnumerable<T> or IInstancesOf<T> to get all implementations of an interface?▼

Use IInstancesOf<T> from Cratis.Types to enumerate implementations of an abstraction, since the framework discovers them by convention. IEnumerable<T> only works when every implementation is hand-registered, which defeats convention-based discovery.

Does this skill cover TypeScript or specification file conventions?▼

No, this skill covers C# only. TypeScript and React questions, specification files using the Establish/Because/should_ pattern, and product API behavior decisions are routed to their own focused workflows.