ContainerResourceBuilderExtensions.WithLifetime<T> Method

Definition

Sets the lifetime behavior of the container resource.

C#
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;

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.

C#
var builder = DistributedApplication.CreateBuilder(args);

builder.AddContainer("mycontainer", "myimage")
       .WithLifetime(ContainerLifetime.Persistent);

builder.Build().Run();

Applies to

Produk Versi
.NET Aspire 9.0.0, 9.1.0