次の方法で共有


ResourceBuilderExtensions.WithHttpsHealthCheck<T> Method

Definition

Adds a health check to the resource which is mapped to a specific endpoint.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WithHttpsHealthCheck<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 WithHttpsHealthCheck : 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 WithHttpsHealthCheck(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.

statusCode
Nullable<Int32>

The result code to interpret as healthy.

endpointName
String

The name of the endpoint to derive the base address from.

Returns

A resource builder.

Examples

This example shows add a HTTPS health check to a backend project to make 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")
                     .WithHttpsHealthCheck("/health");
builder.AddProject<Projects.Backend>("backend")
       .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.

Applies to