Centralized error handling using middleware to avoid repetitive try-catch blocks.
app.UseExceptionHandler("/error");
app.Map("/error", () => Results.Problem("Something went wrong"));
Middleware used for request/response processing like logging or authentication.
public class RequestLoggingMiddleware
{
private readonly RequestDelegate _next;
public RequestLoggingMiddleware(RequestDelegate next) => _next = next;
public async Task Invoke(HttpContext context)
{
Console.WriteLine(context.Request.Path);
await _next(context);
}
}
Controls number of API requests.
builder.Services.AddRateLimiter(options =>
{
options.GlobalLimiter = PartitionedRateLimiter.Create(_ =>
RateLimitPartition.GetFixedWindowLimiter("global", _ => new FixedWindowRateLimiterOptions
{
PermitLimit = 100,
Window = TimeSpan.FromMinutes(1)
}));
});
Default cross-platform web server in ASP.NET Core. Can run standalone or behind Nginx/IIS.
builder.WebHost.UseKestrel();
Real-time communication (chat apps, live updates).
app.MapHub("/chat");
High-performance communication using Protocol Buffers.
app.MapGrpcService();
Runs long background tasks.
public class Worker : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
Console.WriteLine("Running...");
await Task.Delay(10000);
}
}
}
Docker containerizes apps with dependencies for consistent deployment across environments.
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY . .
ENTRYPOINT ["dotnet", "MyApp.dll"]
Docker containerizes apps with dependencies for consistent deployment across environments.
Layered architecture (API, Application, Domain, Infrastructure).
S → Single Responsibility
O → Open/Closed
L → Liskov Substitution
I → Interface Segregation
D → Dependency Inversion
Occurs when threads wait indefinitely for resources held by each other.
lock(obj1)
{
lock(obj2)
{
}
}
Pre-created threads reused to handle multiple requests efficiently
Task.Run(() => DoWork());
[Authorize]
public IActionResult Secure() => Ok("Secure Data");