PostgresBuilderExtensions Methods
Hosting.IDistributedApplicationBuilder. AddDatabase(IResourceBuilder<PostgresServerResource>, string, string?) Section titled AddDatabase(IResourceBuilder<PostgresServerResource>, string, string?) extension IResourceBuilder<PostgresDatabaseResource> public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresDatabaseResource> AddDatabase( this IResourceBuilder<PostgresServerResource> builder, string name, string? databaseName = null) { // ... }}Parameters
builder IResourceBuilder<PostgresServerResource> The PostgreSQL server resource builder. name string The name of the resource. This name will be used as the connection string name when referenced in a dependency. databaseName string? optional The name of the database. If not provided, this defaults to the same value as name. Returns
IResourceBuilder<PostgresDatabaseResource> A reference to the ApplicationModel.IResourceBuilder`1. Remarks
This resource includes built-in health checks. When this resource is referenced as a dependency using the ResourceBuilderExtensions.WaitFor extension method then the dependent resource will wait until the Postgres database is available.
Note that calling PostgresBuilderExtensions.AddDatabase will result in the database being created on the Postgres server when the server becomes ready. The database creation happens automatically as part of the resource lifecycle.
AddPostgres(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>, int?) Section titled AddPostgres(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>, int?) extension IResourceBuilder<PostgresServerResource> public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresServerResource> AddPostgres( this IDistributedApplicationBuilder builder, string name, IResourceBuilder<ParameterResource>? userName = null, IResourceBuilder<ParameterResource>? password = null, int? port = null) { // ... }}Parameters
builder IDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder. name string The name of the resource. This name will be used as the connection string name when referenced in a dependency. userName IResourceBuilder<ParameterResource> optional The parameter used to provide the user name for the PostgreSQL resource. If null a default value will be used. password IResourceBuilder<ParameterResource> optional The parameter used to provide the administrator password for the PostgreSQL resource. If null a random password will be generated. port int? optional The host port used when launching the container. If null a random port will be assigned. Returns
IResourceBuilder<PostgresServerResource> A reference to the ApplicationModel.IResourceBuilder`1. Remarks
This resource includes built-in health checks. When this resource is referenced as a dependency using the ResourceBuilderExtensions.WaitFor extension method then the dependent resource will wait until the Postgres resource is able to service requests.
WithCreationScript(IResourceBuilder<PostgresDatabaseResource>, string) Section titled WithCreationScript(IResourceBuilder<PostgresDatabaseResource>, string) extension IResourceBuilder<PostgresDatabaseResource> public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresDatabaseResource> WithCreationScript( this IResourceBuilder<PostgresDatabaseResource> builder, string script) { // ... }}Parameters
builder IResourceBuilder<PostgresDatabaseResource> The builder for the PostgresDatabaseResource. script string The SQL script used to create the database. Returns
IResourceBuilder<PostgresDatabaseResource> A reference to the ApplicationModel.IResourceBuilder`1. Remarks
CREATE DATABASE "<QUOTED_DATABASE_NAME>"WithDataBindMount(IResourceBuilder<PostgresServerResource>, string, bool) Section titled WithDataBindMount(IResourceBuilder<PostgresServerResource>, string, bool) extension IResourceBuilder<PostgresServerResource> public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresServerResource> WithDataBindMount( this IResourceBuilder<PostgresServerResource> builder, string source, bool isReadOnly = false) { // ... }}Parameters
builder IResourceBuilder<PostgresServerResource> The resource builder. source string The source directory on the host to mount into the container. isReadOnly bool optional A flag that indicates if this is a read-only mount. Returns
IResourceBuilder<PostgresServerResource> The ApplicationModel.IResourceBuilder`1. WithDataVolume(IResourceBuilder<PostgresServerResource>, string?, bool) Section titled WithDataVolume(IResourceBuilder<PostgresServerResource>, string?, bool) extension IResourceBuilder<PostgresServerResource> public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresServerResource> WithDataVolume( this IResourceBuilder<PostgresServerResource> builder, string? name = null, bool isReadOnly = false) { // ... }}Parameters
builder IResourceBuilder<PostgresServerResource> The resource builder. name string? optional The name of the volume. Defaults to an auto-generated name based on the application and resource names. isReadOnly bool optional A flag that indicates if this is a read-only volume. Returns
IResourceBuilder<PostgresServerResource> The ApplicationModel.IResourceBuilder`1. WithHostPort(IResourceBuilder<PgAdminContainerResource>, int?) Section titled WithHostPort(IResourceBuilder<PgAdminContainerResource>, int?) extension IResourceBuilder<PgAdminContainerResource> public static class PostgresBuilderExtensions{ public static IResourceBuilder<PgAdminContainerResource> WithHostPort( this IResourceBuilder<PgAdminContainerResource> builder, int? port) { // ... }}Parameters
builder IResourceBuilder<PgAdminContainerResource> The resource builder for PGAdmin. port int? The port to bind on the host. If null is used random port will be assigned. Returns
IResourceBuilder<PgAdminContainerResource> The resource builder for PGAdmin. WithHostPort(IResourceBuilder<PgWebContainerResource>, int?) Section titled WithHostPort(IResourceBuilder<PgWebContainerResource>, int?) extension IResourceBuilder<PgWebContainerResource> public static class PostgresBuilderExtensions{ public static IResourceBuilder<PgWebContainerResource> WithHostPort( this IResourceBuilder<PgWebContainerResource> builder, int? port) { // ... }}Parameters
builder IResourceBuilder<PgWebContainerResource> The resource builder for pgweb. port int? The port to bind on the host. If null is used random port will be assigned. Returns
IResourceBuilder<PgWebContainerResource> The resource builder for pgweb. WithHostPort(IResourceBuilder<PostgresServerResource>, int?) Section titled WithHostPort(IResourceBuilder<PostgresServerResource>, int?) extension IResourceBuilder<PostgresServerResource> public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresServerResource> WithHostPort( this IResourceBuilder<PostgresServerResource> builder, int? port) { // ... }}Parameters
builder IResourceBuilder<PostgresServerResource> The resource builder. port int? The port to bind on the host. If null is used random port will be assigned. Returns
IResourceBuilder<PostgresServerResource> The ApplicationModel.IResourceBuilder`1. WithInitBindMount(IResourceBuilder<PostgresServerResource>, string, bool) Section titled WithInitBindMount(IResourceBuilder<PostgresServerResource>, string, bool) extension IResourceBuilder<PostgresServerResource> public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresServerResource> WithInitBindMount( this IResourceBuilder<PostgresServerResource> builder, string source, bool isReadOnly = true) { // ... }}Parameters
builder IResourceBuilder<PostgresServerResource> The resource builder. source string The source directory on the host to mount into the container. isReadOnly bool optional A flag that indicates if this is a read-only mount. Returns
IResourceBuilder<PostgresServerResource> The ApplicationModel.IResourceBuilder`1. WithInitFiles(IResourceBuilder<PostgresServerResource>, string) Section titled WithInitFiles(IResourceBuilder<PostgresServerResource>, string) extension IResourceBuilder<PostgresServerResource> public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresServerResource> WithInitFiles( this IResourceBuilder<PostgresServerResource> builder, string source) { // ... }}Parameters
builder IResourceBuilder<PostgresServerResource> The resource builder. source string The source directory or files on the host to copy into the container. Returns
IResourceBuilder<PostgresServerResource> The ApplicationModel.IResourceBuilder`1. WithPassword(IResourceBuilder<PostgresServerResource>, IResourceBuilder<ParameterResource>) Section titled WithPassword(IResourceBuilder<PostgresServerResource>, IResourceBuilder<ParameterResource>) extension IResourceBuilder<PostgresServerResource> public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresServerResource> WithPassword( this IResourceBuilder<PostgresServerResource> builder, IResourceBuilder<ParameterResource> password) { // ... }}Parameters
builder IResourceBuilder<PostgresServerResource> The resource builder. password IResourceBuilder<ParameterResource> The parameter used to provide the password for the PostgreSQL resource. Returns
IResourceBuilder<PostgresServerResource> The ApplicationModel.IResourceBuilder`1. WithPgAdmin(IResourceBuilder<T>, Action<IResourceBuilder<PgAdminContainerResource>>, string?) Section titled WithPgAdmin(IResourceBuilder<T>, Action<IResourceBuilder<PgAdminContainerResource>>, string?) extension IResourceBuilder<T> public static class PostgresBuilderExtensions{ public static IResourceBuilder<T> WithPgAdmin<T>( this IResourceBuilder<T> builder, Action<IResourceBuilder<PgAdminContainerResource>>? configureContainer = null, string? containerName = null) { // ... }}Parameters
builder IResourceBuilder<T> The PostgreSQL server resource builder. configureContainer Action<IResourceBuilder<PgAdminContainerResource>> optional Callback to configure PgAdmin container resource. containerName string? optional The name of the container (Optional). Returns
IResourceBuilder<T> A reference to the ApplicationModel.IResourceBuilder`1. Remarks
WithPgWeb(IResourceBuilder<PostgresServerResource>, Action<IResourceBuilder<PgWebContainerResource>>, string?) Section titled WithPgWeb(IResourceBuilder<PostgresServerResource>, Action<IResourceBuilder<PgWebContainerResource>>, string?) extension IResourceBuilder<PostgresServerResource> public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresServerResource> WithPgWeb( this IResourceBuilder<PostgresServerResource> builder, Action<IResourceBuilder<PgWebContainerResource>>? configureContainer = null, string? containerName = null) { // ... }}Parameters
builder IResourceBuilder<PostgresServerResource> The Postgres server resource builder. configureContainer Action<IResourceBuilder<PgWebContainerResource>> optional Configuration callback for pgweb container resource. containerName string? optional The name of the container (Optional). Returns
IResourceBuilder<PostgresServerResource> A reference to the ApplicationModel.IResourceBuilder`1. Remarks
var builder = DistributedApplication.CreateBuilder(args);
var postgres = builder.AddPostgres("postgres") .WithPgWeb();var db = postgres.AddDatabase("db");
var api = builder.AddProject<Projects.Api>("api") .WithReference(db);
builder.Build().Run();WithUserName(IResourceBuilder<PostgresServerResource>, IResourceBuilder<ParameterResource>) Section titled WithUserName(IResourceBuilder<PostgresServerResource>, IResourceBuilder<ParameterResource>) extension IResourceBuilder<PostgresServerResource> public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresServerResource> WithUserName( this IResourceBuilder<PostgresServerResource> builder, IResourceBuilder<ParameterResource> userName) { // ... }}Parameters
builder IResourceBuilder<PostgresServerResource> The resource builder. userName IResourceBuilder<ParameterResource> The parameter used to provide the user name for the PostgreSQL resource. Returns
IResourceBuilder<PostgresServerResource> The ApplicationModel.IResourceBuilder`1.