.NET 7, targeting November 2022 release, continues the annual release cadence with significant performance improvements, new language features, and enhanced cloud-native capabilities. As an enterprise architect evaluating technology upgrades, this guide focuses on the features that matter most for production systems: performance improvements, Native AOT, rate limiting middleware, and improved minimal API support.
Performance: The Fastest .NET Yet
Each .NET release brings performance improvements, but .NET 7 is exceptional. The team made over 1,000 performance-related commits. Key metrics:
| Benchmark | .NET 6 | .NET 7 | Improvement |
|---|---|---|---|
| JSON Serialization | 145 μs | 98 μs | 32% |
| LINQ FirstOrDefault | 12 ns | 4 ns | 67% |
| Regex (compiled) | 850 ns | 420 ns | 51% |
| GC Pause (p99) | 8 ms | 3 ms | 62% |
Native AOT: Instant Startup
Native AOT (Ahead-of-Time compilation) produces native executables without a JIT compiler. The result: sub-10ms cold starts—critical for serverless and CLI tools.
<PropertyGroup>
<PublishAot>true</PublishAot>
</PropertyGroup>
dotnet publish -c Release -r linux-x64
Constraints:
- No dynamic code generation (reflection limited to trimmer-safe patterns)
- No
Assembly.Loadat runtime - Larger binary size (~10-50MB vs ~5MB self-contained)
Rate Limiting Middleware
.NET 7 adds built-in rate limiting middleware—no third-party packages required:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRateLimiter(options =>
{
options.GlobalLimiter = PartitionedRateLimiter.Create<HttpContext, string>(context =>
RateLimitPartition.GetFixedWindowLimiter(
partitionKey: context.Connection.RemoteIpAddress?.ToString() ?? "unknown",
factory: _ => new FixedWindowRateLimiterOptions
{
PermitLimit = 100,
Window = TimeSpan.FromMinutes(1),
QueueProcessingOrder = QueueProcessingOrder.OldestFirst,
QueueLimit = 10
}));
options.OnRejected = async (context, token) =>
{
context.HttpContext.Response.StatusCode = 429;
await context.HttpContext.Response.WriteAsync(
"Too many requests. Please try again later.", token);
};
});
var app = builder.Build();
app.UseRateLimiter();
app.MapGet("/api/resource", () => "Hello!").RequireRateLimiting("api");
Supported algorithms: Fixed Window, Sliding Window, Token Bucket, Concurrency Limiter.
Minimal APIs: Filters and Grouping
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
// Endpoint groups with shared filters
var api = app.MapGroup("/api")
.AddEndpointFilter<LoggingFilter>()
.AddEndpointFilter<ValidationFilter>();
api.MapGet("/orders", GetOrders)
.RequireAuthorization("read:orders");
api.MapPost("/orders", CreateOrder)
.RequireAuthorization("write:orders")
.AddEndpointFilter<RequestValidationFilter<CreateOrderRequest>>();
// Custom filter implementation
public class LoggingFilter : IEndpointFilter
{
public async ValueTask<object?> InvokeAsync(
EndpointFilterInvocationContext context,
EndpointFilterDelegate next)
{
var logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<LoggingFilter>>();
logger.LogInformation("Request: {Method} {Path}",
context.HttpContext.Request.Method,
context.HttpContext.Request.Path);
var result = await next(context);
logger.LogInformation("Response: {StatusCode}",
context.HttpContext.Response.StatusCode);
return result;
}
}
Key Takeaways
- .NET 7 delivers 10-60% performance improvements across scenarios
- Native AOT enables sub-10ms cold starts
- Built-in rate limiting reduces third-party dependencies
- Minimal API filters enable clean middleware patterns
- Upgrade path from .NET 6 is straightforward
Discover more from C4: Container, Code, Cloud & Context
Subscribe to get the latest posts sent to your email.