Skip to content

biellts/universidade-automatiza / .claude/skills/dotnet-best-practices

dotnet-best-practices

Verified

Ensure .NET/C# code meets best practices for the solution/project.

Siga AGENTS.md; em conflito, AGENTS.md prevalece. Neste projeto: xUnit + Shouldly (sem FluentAssertions/MSTest), erros de negócio via Result (não exceções), datas em DateTimeOffset UTC com TimeProvider (nunca DateTime.Now/DateTime.UtcNow no domínio), escrita por EF Core no DbContext do módulo e leitura por Dapper com IConexaoProvider.

.NET/C# Best Practices

Your task is to ensure .NET/C# code in ${selection} meets the best practices specific to this solution/project. This includes:

Documentation & Structure

  • Follow the established namespace structure: Automatiza.Modules.{Modulo}.Features.{Entidade}s.UseCases.{CasoDeUso} e Automatiza.Modules.{Modulo}.Domain.Entities.{Entidade} (AGENTS.md)
  • Um módulo só acessa o próprio DbContext e o próprio schema; nada de referência entre projetos de módulos

Design Patterns & Architecture

  • Use primary constructor syntax for dependency injection (e.g., public class MyClass(IDependency dependency))
  • Handlers inherit Handler<TRequest, TResponse> and override OnHandle
  • Interfaces follow I{Substantivo}{Papel} (AGENTS.md → Convenções)
  • Aggregates are created only through the static Criar(...) factory

Dependency Injection & Services

  • Register services with appropriate lifetimes (Singleton, Scoped, Transient)
  • Use Microsoft.Extensions.DependencyInjection patterns

Error Messages

  • Domain errors live in {Entidade}Errors classes (Error records with SCREAMING_SNAKE_CASE codes), not resource files

Async/Await Patterns

  • Use async/await for all I/O operations and long-running tasks
  • Return Task or Task from async methods
  • Use ConfigureAwait(false) where appropriate
  • Handle async exceptions properly

Testing Standards

  • Follow AAA pattern (Arrange, Act, Assert)
  • Test both success and failure scenarios
  • Include null parameter validation tests

Configuration & Settings

  • Use strongly-typed configuration classes with data annotations
  • Implement validation attributes (Required, NotEmptyOrWhitespace)
  • Use IConfiguration binding for settings
  • Support appsettings.json configuration files

Error Handling & Logging

  • Use structured logging with Microsoft.Extensions.Logging
  • Include scoped logging with meaningful context
  • Erro de negócio: Result.Fail(...), nunca exceção — exceções ficam para falhas inesperadas/infraestrutura

Performance & Security

  • Use current C# features and .NET 10 optimizations where applicable
  • Implement proper input validation and sanitization
  • Use parameterized queries for database operations (Dapper: parâmetros nomeados e CommandDefinition com CancellationToken)
  • Nunca registre em log senha, token, cookie, e-mail completo ou resposta de avaliação; nunca exponha mensagem de exceção ao cliente
  • Valores monetários e notas em decimal

Code Quality

  • Ensure SOLID principles compliance
  • Avoid code duplication through base classes and utilities
  • Use meaningful names that reflect domain concepts
  • Keep methods focused and cohesive
  • Implement proper disposal patterns for resources
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 322kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 322kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 322kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 322kUpdated Claude CodeCodexVerifiedInstall