ResourceBuilderExtensions.WaitFor<T> Method

Definition

Waits for the dependency resource to enter the Running state before starting the resource.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WaitFor<T> (this Aspire.Hosting.ApplicationModel.IResourceBuilder<T> builder, Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.IResource> dependency) where T : Aspire.Hosting.ApplicationModel.IResourceWithWaitSupport;
static member WaitFor : Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResourceWithWaitSupport)> * Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.IResource> -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResourceWithWaitSupport)> (requires 'T :> Aspire.Hosting.ApplicationModel.IResourceWithWaitSupport)
<Extension()>
Public Function WaitFor(Of T As IResourceWithWaitSupport) (builder As IResourceBuilder(Of T), dependency As IResourceBuilder(Of IResource)) As IResourceBuilder(Of T)

Type Parameters

T

The type of the resource.

Parameters

builder
IResourceBuilder<T>

The resource builder for the resource that will be waiting.

dependency
IResourceBuilder<IResource>

The resource builder for the dependency resource.

Returns

The resource builder.

Examples

Start message queue before starting the worker service.

var builder = DistributedApplication.CreateBuilder(args);
var messaging = builder.AddRabbitMQ("messaging");
builder.AddProject<Projects.MyApp>("myapp")
       .WithReference(messaging)
       .WaitFor(messaging);

Remarks

This method is useful when a resource should wait until another has started running. This can help reduce errors in logs during local development where dependency resources.

Some resources automatically register health checks with the application host container. For these resources, calling WaitFor<T>(IResourceBuilder<T>, IResourceBuilder<IResource>) also results in the resource being blocked from starting until the health checks associated with the dependency resource return Healthy.

The WithHealthCheck<T>(IResourceBuilder<T>, String) method can be used to associate additional health checks with a resource.

Applies to