Unlock powerful built-in features to improve performance, reliability, and maintainability in your ASP.NET Core applications.
ASP.NET Core is full of amazing features, but many developers only use the basics: controllers, middleware, dependency injection, EF Core, and authentication. Hidden inside the framework are powerful tools that can dramatically improve your applications without third-party libraries or complex configurations.
This article explores five underrated features in ASP.NET Core that most developers overlook but should absolutely start using in modern applications. These features include:
Background task processing with
IHostedServiceBuilt-in Health Checks
Endpoint Filters in ASP.NET Core 8
HTTP/3 support
Rate Limiting Middleware
Each of these features can help you build:
Faster apps
More stable APIs
Cleaner architecture
Better user experiences
Let’s dive into each gem in detail.
1. IHostedService for Background Tasks
The first hidden gem is using IHostedService to run recurring background tasks without external libraries like Hangfire or Quartz.
What is IHostedService?
IHostedService allows you to run background processes inside your ASP.NET Core application, such as:
Sending emails
Cleaning up expired records
Processing queues
Generating reports
Sending periodic notifications
And the best part?
No external scheduler required
Runs inside your application lifecycle
How It Works?
The Implementation using a timer to run recurring jobs:
public class BackgroundTask : IHostedService, IDisposable
{
private Timer? _timer;
public Task StartAsync(CancellationToken cancellationToken)
{
_timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromMinutes(1));
return Task.CompletedTask;
}
private void DoWork(object? state)
{
Console.WriteLine("Running background task...");
}
public Task StopAsync(CancellationToken cancellationToken)
{
_timer?.Change(Timeout.Infinite, 0);
return Task.CompletedTask;
}
public void Dispose() => _timer?.Dispose();
}Register it:
builder.Services.AddHostedService<BackgroundTask>();
Join the conversation! Your thoughts help the community grow.