Udostępnij za pośrednictwem


ResourceBuilderExtensions.WaitForCompletion<T> Method

Definition

Waits for the dependency resource to enter the Exited or Finished state before starting the resource.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WaitForCompletion<T> (this Aspire.Hosting.ApplicationModel.IResourceBuilder<T> builder, Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.IResource> dependency, int exitCode = 0) where T : Aspire.Hosting.ApplicationModel.IResourceWithWaitSupport;
static member WaitForCompletion : Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResourceWithWaitSupport)> * Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.IResource> * int -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResourceWithWaitSupport)> (requires 'T :> Aspire.Hosting.ApplicationModel.IResourceWithWaitSupport)
<Extension()>
Public Function WaitForCompletion(Of T As IResourceWithWaitSupport) (builder As IResourceBuilder(Of T), dependency As IResourceBuilder(Of IResource), Optional exitCode As Integer = 0) 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.

exitCode
Int32

The exit code which is interpreted as successful.

Returns

The resource builder.

Examples

Wait for database initialization app to complete running.

var builder = DistributedApplication.CreateBuilder(args);
var pgsql = builder.AddPostgres("postgres");
var dbprep = builder.AddProject<Projects.DbPrepApp>("dbprep")
                    .WithReference(pgsql);
builder.AddProject<Projects.DatabasePrepTool>("dbprep")
       .WithReference(pgsql)
       .WaitForCompletion(dbprep);

Remarks

This method is useful when a resource should wait until another has completed. A common usage pattern would be to include a console application that initializes the database schema or performs other one off initialization tasks.

Note that this method has no impact at deployment time and only works for local development.

Applies to