1- using System . Linq ;
21using Dotnet6 . GraphQL4 . CrossCutting . DependencyInjection . Extensions ;
32using Dotnet6 . GraphQL4 . Domain . Abstractions . DependencyInjection . Extensions ;
4- using Dotnet6 . GraphQL4 . Store . Repositories . Contexts ;
53using Dotnet6 . GraphQL4 . Store . WebAPI . Extensions . EndpointRouteBuilders ;
64using Dotnet6 . GraphQL4 . Repositories . Abstractions . DependencyInjection . Extensions ;
75using Dotnet6 . GraphQL4 . Repositories . Abstractions . DependencyInjection . Options ;
108using Dotnet6 . GraphQL4 . Store . Repositories . DependencyInjection . Options ;
119using Dotnet6 . GraphQL4 . Store . WebAPI . DependencyInjection . Extensions ;
1210using Dotnet6 . GraphQL4 . Store . WebAPI . Graphs ;
13- using HealthChecks . UI . Client ;
1411using Microsoft . AspNetCore . Builder ;
1512using Microsoft . AspNetCore . Hosting ;
13+ using Microsoft . AspNetCore . HttpLogging ;
1614using Microsoft . AspNetCore . Server . Kestrel . Core ;
17- using Microsoft . EntityFrameworkCore ;
1815using Microsoft . Extensions . Configuration ;
1916using Microsoft . Extensions . DependencyInjection ;
20- using Microsoft . Extensions . Diagnostics . HealthChecks ;
2117using Microsoft . Extensions . Hosting ;
2218using Microsoft . Extensions . Logging ;
2319using Serilog ;
@@ -28,8 +24,6 @@ public class Startup
2824 {
2925 private readonly IConfiguration _configuration ;
3026 private readonly IWebHostEnvironment _env ;
31- private readonly string [ ] _readinessTags = { "ready" } ;
32- private readonly string [ ] _livenessTags = { "live" } ;
3327
3428 public Startup ( IConfiguration configuration , IWebHostEnvironment env )
3529 {
@@ -43,10 +37,10 @@ public void Configure(IApplicationBuilder app , ILoggerFactory loggerFactory)
4337 app . UseDeveloperExceptionPage ( ) ;
4438
4539 loggerFactory . AddSerilog ( ) ;
46-
47- app . UseApplicationExceptionHandler ( ) ;
48-
49- app . UseSerilogRequestLogging ( )
40+
41+ app . UseHttpLogging ( )
42+ . UseApplicationExceptionHandler ( )
43+ . UseSerilogRequestLogging ( )
5044 . UseApplicationGraphQL < StoreSchema > ( )
5145 . UseRouting ( )
5246 . UseEndpoints (
@@ -59,36 +53,29 @@ public void Configure(IApplicationBuilder app , ILoggerFactory loggerFactory)
5953 configurationRoot : _configuration as IConfigurationRoot ,
6054 isProduction : _env . IsProduction ( ) ) ;
6155
62- endpoints . MapApplicationHealthChecks (
63- pattern : _configuration [ "HealthChecksPatterns:Health" ] ,
64- predicate : registration
65- => registration . Tags . Any ( ) is false ) ;
66-
67- endpoints . MapApplicationHealthChecks (
68- pattern : _configuration [ "HealthChecksPatterns:Liveness" ] ,
69- predicate : registration
70- => registration . Tags . Any ( item
71- => _livenessTags . Contains ( item ) ) ) ;
56+ endpoints . MapHealthCheck (
57+ pattern : _configuration [ "HealthChecksPatterns:Health" ] ) ;
7258
73- endpoints . MapApplicationHealthChecks (
74- pattern : _configuration [ "HealthChecksPatterns:Readiness" ] ,
75- predicate : registration
76- => registration . Tags . Any ( item
77- => _readinessTags . Contains ( item ) ) ) ;
59+ endpoints . MapLivenessHealthCheck (
60+ pattern : _configuration [ "HealthChecksPatterns:Liveness" ] ) ;
7861
79- endpoints . MapHealthChecks (
80- pattern : _configuration [ "HealthChecksPatterns:UI" ] ,
81- options : new ( ) { ResponseWriter = UIResponseWriter . WriteHealthCheckUIResponse } ) ;
62+ endpoints . MapReadinessHealthCheck (
63+ pattern : _configuration [ "HealthChecksPatterns:Readiness" ] ) ;
8264 } ) ;
8365 }
8466
8567 public void ConfigureServices ( IServiceCollection services )
8668 {
87- services . ConfigureTransactionOptions ( _configuration . GetSection ( nameof ( TransactionOptions ) ) ) ;
88- services . ConfigureSqlServerRetryingOptions ( _configuration . GetSection ( nameof ( SqlServerRetryingOptions ) ) ) ;
69+ services . ConfigureTransactionOptions (
70+ section : _configuration . GetSection ( nameof ( TransactionOptions ) ) ) ;
71+
72+ services . ConfigureSqlServerRetryingOptions (
73+ section : _configuration . GetSection ( nameof ( SqlServerRetryingOptions ) ) ) ;
74+
75+ services . AddHttpLogging ( options
76+ => options . LoggingFields = HttpLoggingFields . RequestProperties ) ;
8977
90- services
91- . AddLogging ( )
78+ services . AddLogging ( )
9279 . AddBuilders ( )
9380 . AddRepositories ( )
9481 . AddUnitOfWork ( )
@@ -100,22 +87,11 @@ public void ConfigureServices(IServiceCollection services)
10087 . AddApplicationDbContext ( )
10188 . AddControllers ( ) ;
10289
90+ services . AddDbContextHealthChecks ( ) ;
10391 services . AddApplicationGraphQL ( ) ;
10492
10593 services . Configure < KestrelServerOptions > ( options
10694 => options . AllowSynchronousIO = true ) ;
107-
108- services . AddHealthChecks ( )
109- . AddDbContextCheck < DbContext > (
110- name : "Sql Server (Live)" ,
111- failureStatus : HealthStatus . Degraded ,
112- tags : _livenessTags )
113- . AddDbContextCheck < StoreDbContext > (
114- name : "Sql Server (Ready)" ,
115- failureStatus : HealthStatus . Unhealthy ,
116- tags : _readinessTags ,
117- customTestQuery : ( dbContext , cancellationToken )
118- => dbContext . Products . AnyAsync ( cancellationToken ) ) ;
11995 }
12096 }
12197}
0 commit comments