Shared service defaults for .NET Aspire applications including OpenTelemetry, Health Checks, Resilience, and Service Discovery configurations.
- 📊 OpenTelemetry Integration - Complete telemetry setup with logging, metrics, and tracing
- 🏥 Health Checks - Pre-configured health check endpoints (
/healthand/alive) - 🔄 Resilience - HTTP resilience handlers with retry policies
- 🔍 Service Discovery - Built-in service discovery support
- 🌐 Gateway Extensions - API Gateway specific configurations (caching, compression)
- .NET 8.0
- .NET 9.0
- .NET 10.0
dotnet add package Miccore.Clean.ServiceDefaultsOr via Package Manager Console:
Install-Package Miccore.Clean.ServiceDefaultsIn your Program.cs:
var builder = WebApplication.CreateBuilder(args);
// Add service defaults (OpenTelemetry, Health Checks, Service Discovery, Resilience)
builder.AddServiceDefaults();
// Add your other services...
builder.Services.AddControllers();
var app = builder.Build();
// Map default endpoints (health checks)
app.MapDefaultEndpoints();
// Map your other endpoints...
app.MapControllers();
app.Run();Configures the complete set of service defaults:
builder.AddServiceDefaults();This includes:
- OpenTelemetry (logging, metrics, tracing)
- Health checks
- Service discovery
- HTTP resilience
Maps the health check endpoints:
app.MapDefaultEndpoints();Exposes:
/health- Full health check/alive- Liveness probe
For API Gateway services, use additional gateway extensions:
builder.AddServiceDefaults();
builder.AddGatewayDefaults(); // Adds caching, compression, etc.The package automatically configures OpenTelemetry based on environment variables:
| Variable | Description |
|---|---|
OTEL_EXPORTER_OTLP_ENDPOINT |
OTLP exporter endpoint |
OTEL_SERVICE_NAME |
Service name for telemetry |
Health check endpoints are automatically mapped:
/health- Returns detailed health status/alive- Simple liveness check for Kubernetes probes
using Miccore.Clean.ServiceDefaults;
var builder = WebApplication.CreateBuilder(args);
// Add all service defaults
builder.AddServiceDefaults();
// Add application services
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure pipeline
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
// Map health endpoints
app.MapDefaultEndpoints();
// Map your API endpoints
app.MapGet("/api/hello", () => "Hello World!");
app.Run();This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any issues, please open an issue on GitHub.