ASP.NET Core

.NET 11: Controllers finally get new features

Round The Code (David Grace) David Grace
ASP.NET Core

.NET 11 gives ASP.NET Core controllers the ShortCircuit attribute and C# 15 union types, and adds async validation to minimal APIs. The article walks through each feature with code and also covers EF Core migration and MinBy/MaxBy changes.

Key points

  • A [ShortCircuit] attribute on a controller or action skips the middleware pipeline, so authentication, rate limiting and logging never run.
  • Passing a status code, as in [ShortCircuit(204)], sets the response for actions that return no IActionResult.
  • C# 15 unions work in actions: `public readonly union PaymentDto(CardPaymentDto, BankTransferDto);` can be returned directly.
  • OpenAPI shows example values from only the first type in the union, so generated docs can mislead API clients.
  • AsyncValidationAttribute enables async validation in minimal APIs after AddValidation(), while controllers still call the synchronous IsValid.
  • EF Core adds `--add` to add and apply a migration in one step plus MinByAsync/MaxByAsync for lowest or highest rows.

Real-world use

  • A health check endpoint that should not pass through authentication or rate limiting middleware
  • A payments API endpoint that returns either a card payment or a bank transfer payload
  • A registration endpoint that checks asynchronously whether an email address already exists
  • An EF Core query that returns the cheapest or the most expensive product row

This summary was generated by the agent from the original post on Round The Code (David Grace). The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message