Service defaults are a shared class library of startup extension methods for Aspire applications. They provide common capabilities such as service discovery, health assessment, metrics collection, and other shared functionality. The library can be modified to fit an application's needs, including replacing its metrics or health-check mechanisms. section 1.8
To use service defaults in an ASP.NET Core service:
- Reference the Service Defaults project and call AddServiceDefaults() during the builder phase. section 10.2
- Call MapDefaultEndpoints() in the request pipeline to expose health-check and other shared endpoints. section 10.2
- The class library needs the Microsoft.AspNetCore.App framework reference and packages for the capabilities it uses. section 1.8
builder.AddServiceDefaults();
Startup registration adds the shared Aspire dependencies to a service. section 10.2
app.MapDefaultEndpoints();
Pipeline registration exposes the shared endpoints, including health checks. section 10.2
