Partilhar via


ContainerResourceBuilderExtensions.WithLifetime<T> Method

Definition

Sets the lifetime behavior of the container resource.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WithLifetime<T> (this Aspire.Hosting.ApplicationModel.IResourceBuilder<T> builder, Aspire.Hosting.ApplicationModel.ContainerLifetime lifetime) where T : Aspire.Hosting.ApplicationModel.ContainerResource;
static member WithLifetime : Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.ContainerResource)> * Aspire.Hosting.ApplicationModel.ContainerLifetime -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.ContainerResource)> (requires 'T :> Aspire.Hosting.ApplicationModel.ContainerResource)
<Extension()>
Public Function WithLifetime(Of T As ContainerResource) (builder As IResourceBuilder(Of T), lifetime As ContainerLifetime) As IResourceBuilder(Of T)

Type Parameters

T

The resource type.

Parameters

builder
IResourceBuilder<T>

Builder for the container resource.

lifetime
ContainerLifetime

The lifetime behavior of the container resource. The defaults behavior is Session.

Returns

The IResourceBuilder<T>.

Examples

Marking a container resource to have a Persistent lifetime.

var builder = DistributedApplication.CreateBuilder(args);
builder.AddContainer("mycontainer", "myimage")
       .WithContainerLifetime(ContainerLifetimeType.Persistent);

Applies to