@@ -31,6 +31,9 @@ public static IResourceBuilder<PostgresServerResource> AddPostgres(this IDistrib
3131 IResourceBuilder < ParameterResource > ? password = null ,
3232 int ? port = null )
3333 {
34+ ArgumentNullException . ThrowIfNull ( builder ) ;
35+ ArgumentNullException . ThrowIfNull ( name ) ;
36+
3437 var passwordParameter = password ? . Resource ?? ParameterResourceBuilderExtensions . CreateDefaultPasswordParameter ( builder , $ "{ name } -password") ;
3538
3639 var postgresServer = new PostgresServerResource ( name , userName ? . Resource , passwordParameter ) ;
@@ -56,6 +59,9 @@ public static IResourceBuilder<PostgresServerResource> AddPostgres(this IDistrib
5659 /// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
5760 public static IResourceBuilder < PostgresDatabaseResource > AddDatabase ( this IResourceBuilder < PostgresServerResource > builder , string name , string ? databaseName = null )
5861 {
62+ ArgumentNullException . ThrowIfNull ( builder ) ;
63+ ArgumentNullException . ThrowIfNull ( name ) ;
64+
5965 // Use the resource name as the database name if it's not provided
6066 databaseName ??= name ;
6167
@@ -73,6 +79,8 @@ public static IResourceBuilder<PostgresDatabaseResource> AddDatabase(this IResou
7379 /// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
7480 public static IResourceBuilder < T > WithPgAdmin < T > ( this IResourceBuilder < T > builder , Action < IResourceBuilder < PgAdminContainerResource > > ? configureContainer = null , string ? containerName = null ) where T : PostgresServerResource
7581 {
82+ ArgumentNullException . ThrowIfNull ( builder ) ;
83+
7684 if ( builder . ApplicationBuilder . Resources . OfType < PgAdminContainerResource > ( ) . SingleOrDefault ( ) is { } existingPgAdminResource )
7785 {
7886 var builderForExistingResource = builder . ApplicationBuilder . CreateResourceBuilder ( existingPgAdminResource ) ;
@@ -108,6 +116,8 @@ public static IResourceBuilder<T> WithPgAdmin<T>(this IResourceBuilder<T> builde
108116 /// <returns>The resource builder for PGAdmin.</returns>
109117 public static IResourceBuilder < PgAdminContainerResource > WithHostPort ( this IResourceBuilder < PgAdminContainerResource > builder , int ? port )
110118 {
119+ ArgumentNullException . ThrowIfNull ( builder ) ;
120+
111121 return builder . WithEndpoint ( "http" , endpoint =>
112122 {
113123 endpoint . Port = port ;
@@ -133,7 +143,12 @@ private static void SetPgAdminEnvironmentVariables(EnvironmentCallbackContext co
133143 /// <param name="isReadOnly">A flag that indicates if this is a read-only volume.</param>
134144 /// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
135145 public static IResourceBuilder < PostgresServerResource > WithDataVolume ( this IResourceBuilder < PostgresServerResource > builder , string ? name = null , bool isReadOnly = false )
136- => builder . WithVolume ( name ?? VolumeNameGenerator . CreateVolumeName ( builder , "data" ) , "/var/lib/postgresql/data" , isReadOnly ) ;
146+ {
147+ ArgumentNullException . ThrowIfNull ( builder ) ;
148+
149+ return builder . WithVolume ( name ?? VolumeNameGenerator . CreateVolumeName ( builder , "data" ) ,
150+ "/var/lib/postgresql/data" , isReadOnly ) ;
151+ }
137152
138153 /// <summary>
139154 /// Adds a bind mount for the data folder to a PostgreSQL container resource.
@@ -143,7 +158,12 @@ public static IResourceBuilder<PostgresServerResource> WithDataVolume(this IReso
143158 /// <param name="isReadOnly">A flag that indicates if this is a read-only mount.</param>
144159 /// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
145160 public static IResourceBuilder < PostgresServerResource > WithDataBindMount ( this IResourceBuilder < PostgresServerResource > builder , string source , bool isReadOnly = false )
146- => builder . WithBindMount ( source , "/var/lib/postgresql/data" , isReadOnly ) ;
161+ {
162+ ArgumentNullException . ThrowIfNull ( builder ) ;
163+ ArgumentNullException . ThrowIfNull ( source ) ;
164+
165+ return builder . WithBindMount ( source , "/var/lib/postgresql/data" , isReadOnly ) ;
166+ }
147167
148168 /// <summary>
149169 /// Adds a bind mount for the init folder to a PostgreSQL container resource.
@@ -153,5 +173,10 @@ public static IResourceBuilder<PostgresServerResource> WithDataBindMount(this IR
153173 /// <param name="isReadOnly">A flag that indicates if this is a read-only mount.</param>
154174 /// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
155175 public static IResourceBuilder < PostgresServerResource > WithInitBindMount ( this IResourceBuilder < PostgresServerResource > builder , string source , bool isReadOnly = true )
156- => builder . WithBindMount ( source , "/docker-entrypoint-initdb.d" , isReadOnly ) ;
176+ {
177+ ArgumentNullException . ThrowIfNull ( builder ) ;
178+ ArgumentNullException . ThrowIfNull ( source ) ;
179+
180+ return builder . WithBindMount ( source , "/docker-entrypoint-initdb.d" , isReadOnly ) ;
181+ }
157182}
0 commit comments