次の方法で共有


AzurePostgresExtensions.AddAzurePostgresFlexibleServer Method

Definition

Adds an Azure PostgreSQL Flexible Server resource to the application model.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Azure.AzurePostgresFlexibleServerResource> AddAzurePostgresFlexibleServer (this Aspire.Hosting.IDistributedApplicationBuilder builder, string name);
static member AddAzurePostgresFlexibleServer : Aspire.Hosting.IDistributedApplicationBuilder * string -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.Azure.AzurePostgresFlexibleServerResource>
<Extension()>
Public Function AddAzurePostgresFlexibleServer (builder As IDistributedApplicationBuilder, name As String) As IResourceBuilder(Of AzurePostgresFlexibleServerResource)

Parameters

builder
IDistributedApplicationBuilder

The builder for the distributed application.

name
String

The name of the resource.

Returns

A reference to the IResourceBuilder<T> builder.

Examples

The following example creates an Azure PostgreSQL Flexible Server resource and referencing that resource in a .NET project.

var builder = DistributedApplication.CreateBuilder(args);

var data = builder.AddAzurePostgresFlexibleServer("data");

builder.AddProject<Projects.ProductService>()
    .WithReference(data);

builder.Build().Run();

Remarks

By default, the Azure PostgreSQL Flexible Server resource is configured to use Microsoft Entra ID (Azure Active Directory) for authentication. This requires changes to the application code to use an azure credential to authenticate with the resource. See https://learn.microsoft.com/azure/postgresql/flexible-server/how-to-connect-with-managed-identity#connect-using-managed-identity-in-c for more information.

You can use the WithPasswordAuthentication(IResourceBuilder<AzurePostgresFlexibleServerResource>, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>) method to configure the resource to use password authentication.

Applies to