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)
72
72
return builder ;
73
73
}
74
74
75
+ [ Obsolete ( "This method is deprecated. Please indicate the TypeDescriptors as indicated in the README" , true ) ]
75
76
public static IServiceCollection AddDateTimeOnlyAttributes ( this IServiceCollection services )
76
77
{
77
78
TypeDescriptor . AddAttributes ( typeof ( DateOnly ) , new TypeConverterAttribute ( typeof ( DateOnlyTypeConverter ) ) ) ;
@@ -167,6 +168,27 @@ public static IServiceCollection AddMySqlHealthChecks(this IServiceCollection se
167
168
return services ;
168
169
}
169
170
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
+
170
192
public static IEndpointRouteBuilder AddDatabaseHealthChecks ( this IEndpointRouteBuilder builder , string pattern )
171
193
{
172
194
builder . MapHealthChecks ( pattern , new HealthCheckOptions
You can’t perform that action at this time.
0 commit comments