ResourceBuilderExtensions.WithHttpHealthCheck<T> Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Adds a health check to the resource which is mapped to a specific endpoint.
public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WithHttpHealthCheck<T>(this Aspire.Hosting.ApplicationModel.IResourceBuilder<T> builder, string? path = default, int? statusCode = default, string? endpointName = default) where T : Aspire.Hosting.ApplicationModel.IResourceWithEndpoints;
static member WithHttpHealthCheck : Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResourceWithEndpoints)> * string * Nullable<int> * string -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResourceWithEndpoints)> (requires 'T :> Aspire.Hosting.ApplicationModel.IResourceWithEndpoints)
<Extension()>
Public Function WithHttpHealthCheck(Of T As IResourceWithEndpoints) (builder As IResourceBuilder(Of T), Optional path As String = Nothing, Optional statusCode As Nullable(Of Integer) = Nothing, Optional endpointName As String = Nothing) As IResourceBuilder(Of T)
Type Parameters
- T
A resource type that implements IResourceWithEndpoints.
Parameters
- builder
- IResourceBuilder<T>
A resource builder.
- path
- String
The relative path to test.
- endpointName
- String
The name of the endpoint to derive the base address from.
Returns
The IResourceBuilder<T>.
Examples
This example shows adding an HTTP health check to a backend project. The health check makes sure that the front end does not start until the backend is reporting a healthy status based on the return code returned from the "/health" path on the backend server.
var builder = DistributedApplication.CreateBuilder(args);
var backend = builder.AddProject<Projects.Backend>("backend")
.WithHttpHealthCheck("/health");
builder.AddProject<Projects.Frontend>("frontend")
.WithReference(backend).WaitFor(backend);
Remarks
This method adds a health check to the health check service which polls the specified endpoint on the resource on a periodic basis. The base address is dynamically determined based on the endpoint that was selected. By default the path is set to "/" and the status code is set to 200.