Udostępnij za pośrednictwem


ResourceBuilderExtensions.WithHttpHealthCheck Method

Definition

Overloads

WithHttpHealthCheck<T>(IResourceBuilder<T>, Func<EndpointReference>, String, Nullable<Int32>)

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

WithHttpHealthCheck<T>(IResourceBuilder<T>, String, Nullable<Int32>, String)

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

WithHttpHealthCheck<T>(IResourceBuilder<T>, Func<EndpointReference>, String, Nullable<Int32>)

Source:
ResourceBuilderExtensions.cs

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, Func<Aspire.Hosting.ApplicationModel.EndpointReference>? endpointSelector, string? path = default, int? statusCode = default) where T : Aspire.Hosting.ApplicationModel.IResourceWithEndpoints;
static member WithHttpHealthCheck : Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResourceWithEndpoints)> * Func<Aspire.Hosting.ApplicationModel.EndpointReference> * string * Nullable<int> -> 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), endpointSelector As Func(Of EndpointReference), Optional path As String = Nothing, Optional statusCode As Nullable(Of Integer) = Nothing) As IResourceBuilder(Of T)

Type Parameters

T

A resource type that implements IResourceWithEndpoints.

Parameters

builder
IResourceBuilder<T>

A resource builder.

endpointSelector
Func<EndpointReference>
path
String

The relative path to test.

statusCode
Nullable<Int32>

The result code to interpret as healthy.

Returns

The IResourceBuilder<T>.

Remarks

This method adds a health check to the health check service which polls the specified endpoint 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.

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");
backend.WithHttpHealthCheck(() => backend.GetEndpoint("https"), path: "/health")
builder.AddProject<Projects.Frontend>("frontend")
       .WithReference(backend).WaitFor(backend);

Applies to

WithHttpHealthCheck<T>(IResourceBuilder<T>, String, Nullable<Int32>, String)

Source:
ResourceBuilderExtensions.cs
Source:
ResourceBuilderExtensions.cs
Source:
ResourceBuilderExtensions.cs
Source:
ResourceBuilderExtensions.cs

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.

statusCode
Nullable<Int32>

The result code to interpret as healthy.

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.

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);

Applies to