This repository was archived by the owner on Apr 17, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
src/NET6CustomLibrary/Extensions Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ public static IMvcBuilder AddDateTimeJsonOptions(this IMvcBuilder builder)
7272 return builder ;
7373 }
7474
75+ [ Obsolete ( "This method is deprecated. Please indicate the TypeDescriptors as indicated in the README" , true ) ]
7576 public static IServiceCollection AddDateTimeOnlyAttributes ( this IServiceCollection services )
7677 {
7778 TypeDescriptor . AddAttributes ( typeof ( DateOnly ) , new TypeConverterAttribute ( typeof ( DateOnlyTypeConverter ) ) ) ;
@@ -167,6 +168,27 @@ public static IServiceCollection AddMySqlHealthChecks(this IServiceCollection se
167168 return services ;
168169 }
169170
171+ public static IServiceCollection AddPostgresHealthChecks ( this IServiceCollection services , string connectionString , string nameAsyncCheck )
172+ {
173+ services . AddHealthChecks ( )
174+ . AddAsyncCheck ( nameAsyncCheck , async ( ) =>
175+ {
176+ try
177+ {
178+ using var connection = new NpgsqlConnection ( connectionString ) ;
179+ await connection . OpenAsync ( ) ;
180+ }
181+ catch ( Exception ex )
182+ {
183+ return HealthCheckResult . Unhealthy ( ex . Message , ex ) ;
184+ }
185+
186+ return HealthCheckResult . Healthy ( ) ;
187+ } ) ;
188+
189+ return services ;
190+ }
191+
170192 public static IEndpointRouteBuilder AddDatabaseHealthChecks ( this IEndpointRouteBuilder builder , string pattern )
171193 {
172194 builder . MapHealthChecks ( pattern , new HealthCheckOptions
You can’t perform that action at this time.
0 commit comments