home / skills / stuartf303 / sorcha / dotnet

dotnet skill

/.claude/skills/dotnet

This skill helps configure .NET 10 projects with modern C# features, DI patterns, and shared service defaults for consistent setups.

npx playbooks add skill stuartf303/sorcha --skill dotnet

Review the files below or copy the command above to add this skill to your agents.

Files (3)
SKILL.md
3.3 KB
---
name: dotnet
description: |
  Manages .NET 10 runtime, C# 13 syntax, and project configuration
  Use when: configuring projects, using modern C# features, setting up service defaults, working with DI patterns
allowed-tools: Read, Edit, Write, Glob, Grep, Bash, mcp__context7__resolve-library-id, mcp__context7__query-docs
---

# .NET 10 / C# 13 Skill

This codebase uses .NET 10 (LTS) with C# 13, configured with strict nullable reference types, implicit usings, and XML documentation. All services follow the same project configuration patterns and share infrastructure through `Sorcha.ServiceDefaults`.

## Quick Start

### Project Configuration

```xml
<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <NoWarn>$(NoWarn);CS1591</NoWarn>
  </PropertyGroup>
</Project>
```

### Service Setup Pattern

```csharp
var builder = WebApplication.CreateBuilder(args);

// Always call AddServiceDefaults first
builder.AddServiceDefaults();

// Add service-specific dependencies
builder.Services.AddScoped<IMyService, MyService>();

// Add JWT authentication (shared from ServiceDefaults)
builder.AddJwtAuthentication();

var app = builder.Build();
app.MapDefaultEndpoints();
app.UseAuthentication();
app.UseAuthorization();
```

## Key Concepts

| Concept | Usage | Example |
|---------|-------|---------|
| Primary constructors | Services with DI | `class MyService(IRepo repo)` |
| Collection expressions | Default values | `List<T> Items = []` |
| Required members | DTOs/contracts | `public required string Id { get; set; }` |
| Records | Value objects, DTOs | `public record PagedResult<T>(...)` |
| Raw string literals | Multi-line docs | `"""Markdown content"""` |

## Common Patterns

### Global Usings

```csharp
// GlobalUsings.cs
global using System;
global using System.Collections.Generic;
global using System.Linq;
global using System.Threading;
global using System.Threading.Tasks;
global using Sorcha.MyProject.Domain;  // Project-specific
```

### Test Project Setup

```xml
<ItemGroup>
  <Using Include="Xunit" />
  <Using Include="Moq" />
  <Using Include="FluentAssertions" />
</ItemGroup>
```

## See Also

- [patterns](references/patterns.md) - C# 13 features and code patterns
- [workflows](references/workflows.md) - Build, test, and deployment workflows

## Related Skills

- **aspire** - .NET Aspire orchestration and service defaults
- **minimal-apis** - Endpoint configuration with MapGet/MapPost
- **xunit** - Test project configuration and patterns
- **entity-framework** - EF Core integration with repositories

## Documentation Resources

> Fetch latest .NET documentation with Context7.

**How to use Context7:**
1. Use `mcp__context7__resolve-library-id` to search for "dotnet"
2. **Prefer website documentation** (IDs starting with `/websites/`) over source code repositories when available
3. Query with `mcp__context7__query-docs` using the resolved library ID

**Library ID:** `/websites/learn_microsoft_en-us_dotnet` _(high reputation, 42K+ snippets)_

**Recommended Queries:**
- "C# 13 new features primary constructors"
- "collection expressions syntax"
- "required members properties"
- "nullable reference types"

Overview

This skill manages .NET 10 runtime, C# 13 syntax, and consistent project configuration for services. It provides opinionated defaults for nullable reference types, implicit usings, XML docs, and a shared ServiceDefaults setup to streamline service bootstrapping. Use it to standardize DI patterns, authentication, and project templates across services.

How this skill works

The skill inspects and enforces project SDK settings (TargetFramework net10.0, ImplicitUsings, Nullable, GenerateDocumentationFile) and supplies a ServiceDefaults extension that must be applied early in WebApplication builder configuration. It wires common middleware, JWT authentication helpers, and exposes shared global usings and test project patterns to keep services consistent. C# 13 language features like primary constructors, collection expressions, required members, and raw string literals are expected and supported.

When to use it

  • Setting up a new .NET 10 web service with consistent defaults and documentation generation
  • Refactoring projects to adopt C# 13 features (primary constructors, collection expressions, required members)
  • Configuring dependency injection and shared authentication across microservices
  • Preparing test projects with standard using directives and test libraries
  • Enforcing nullable reference types and implicit usings across a codebase

Best practices

  • Call AddServiceDefaults on the builder before adding service-specific dependencies
  • Enable GenerateDocumentationFile and suppress only CS1591 to keep XML docs clean
  • Prefer primary constructors for DI-enabled services to reduce boilerplate
  • Use required members on DTOs to ensure construction-time validity
  • Keep shared global usings limited to common, stable namespaces to avoid coupling

Example use cases

  • Bootstrapping a new API: create project file with net10.0 settings, register ServiceDefaults, add scoped services, map endpoints, and enable auth
  • Migrating older services to C# 13: adopt primary constructors and collection expressions to simplify models and defaults
  • Standardizing tests: add global Using entries for Xunit, Moq, and FluentAssertions across test projects
  • Implementing DTO contracts: use records and required members for clear, immutable contracts
  • Documenting public APIs: enable XML documentation generation and include raw string literals for multi-line docs

FAQ

Do I have to call AddServiceDefaults first?

Yes. AddServiceDefaults sets up shared middleware and authentication that other registrations rely on.

Is nullable reference types required?

The configuration enforces Nullable enable to improve null-safety and align code expectations across services.