共用方式為


ProjectResourceBuilderExtensions.WithReplicas Method

Definition

Configures how many replicas of the project should be created for the project.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ProjectResource> WithReplicas (this Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ProjectResource> builder, int replicas);
static member WithReplicas : Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ProjectResource> * int -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ProjectResource>
<Extension()>
Public Function WithReplicas (builder As IResourceBuilder(Of ProjectResource), replicas As Integer) As IResourceBuilder(Of ProjectResource)

Parameters

builder
IResourceBuilder<ProjectResource>

The project resource builder.

replicas
Int32

The number of replicas.

Returns

A reference to the IResourceBuilder<T>.

Examples

Start multiple instances of the same service.

var builder = DistributedApplication.CreateBuilder(args);

builder.AddProject<Projects.InventoryService>("inventoryservice")
       .WithReplicas(3);

Remarks

When this method is applied to a project resource it will configure the app host to start multiple instances of the application based on the specified number of replicas. By default the app host automatically starts a reverse proxy for each process. When WithReplicas(IResourceBuilder<ProjectResource>, Int32) is used the reverse proxy will load balance traffic between the replicas.

This capability can be useful when debugging scale out scenarios to ensure state is appropriately managed within a cluster of instances.

Applies to