@@ -5,74 +5,77 @@ namespace GZCTF.Extensions.Startup;
55
66static class AppBuilderExtensions
77{
8- internal static void ConfigureWebHost ( this WebApplicationBuilder builder )
8+ extension ( WebApplicationBuilder builder )
99 {
10- builder . Services . ConfigureHttpJsonOptions ( options =>
10+ internal void ConfigureWebHost ( )
1111 {
12- options . SerializerOptions . ConfigCustomSerializerOptions ( ) ;
13- } ) ;
14-
15- builder . Services . AddLocalization ( options => options . ResourcesPath = "Resources" )
16- . Configure < RequestLocalizationOptions > ( options =>
12+ builder . Services . ConfigureHttpJsonOptions ( options =>
1713 {
18- options
19- . AddSupportedCultures ( SupportedCultures )
20- . AddSupportedUICultures ( SupportedCultures ) ;
21-
22- options . ApplyCurrentCultureToResponseHeaders = true ;
14+ options . SerializerOptions . ConfigCustomSerializerOptions ( ) ;
2315 } ) ;
2416
25- builder . WebHost . ConfigureKestrel ( options =>
26- {
27- var kestrelSection = builder . Configuration . GetSection ( "Kestrel" ) ;
28- options . Configure ( kestrelSection ) ;
29- kestrelSection . Bind ( options ) ;
30- } ) . UseKestrel ( options =>
31- {
32- options . ListenAnyIP ( ServerPort ) ;
33- options . ListenAnyIP ( MetricPort ) ;
34- } ) ;
17+ builder . Services . AddLocalization ( options => options . ResourcesPath = "Resources" )
18+ . Configure < RequestLocalizationOptions > ( options =>
19+ {
20+ options
21+ . AddSupportedCultures ( SupportedCultures )
22+ . AddSupportedUICultures ( SupportedCultures ) ;
3523
36- builder . Logging . ClearProviders ( ) ;
37- builder . Logging . SetMinimumLevel ( LogLevel . Trace ) ;
38- builder . Logging . AddSerilog ( dispose : true ) ;
39- builder . Host . UseSerilog ( dispose : true ) ;
40- builder . Configuration . AddEnvironmentVariables ( "GZCTF_" ) ;
24+ options . ApplyCurrentCultureToResponseHeaders = true ;
25+ } ) ;
4126
42- builder . Services . AddServiceDiscovery ( ) ;
43- builder . Services . ConfigureHttpClientDefaults ( http =>
44- {
45- http . AddStandardResilienceHandler ( ) ;
46- http . AddServiceDiscovery ( ) ;
47- } ) ;
48- }
49-
50- internal static void ConfigureCacheAndSignalR ( this WebApplicationBuilder builder )
51- {
52- var signalrBuilder = builder . Services . AddSignalR ( ) . AddJsonProtocol ( options =>
53- {
54- options . PayloadSerializerOptions . ConfigCustomSerializerOptions ( ) ;
55- } ) ;
27+ builder . WebHost . ConfigureKestrel ( options =>
28+ {
29+ var kestrelSection = builder . Configuration . GetSection ( "Kestrel" ) ;
30+ options . Configure ( kestrelSection ) ;
31+ kestrelSection . Bind ( options ) ;
32+ } ) . UseKestrel ( options =>
33+ {
34+ options . ListenAnyIP ( ServerPort ) ;
35+ options . ListenAnyIP ( MetricPort ) ;
36+ } ) ;
5637
57- var connectionString = builder . Configuration . GetConnectionString ( "RedisCache" ) ;
38+ builder . Logging . ClearProviders ( ) ;
39+ builder . Logging . SetMinimumLevel ( LogLevel . Trace ) ;
40+ builder . Logging . AddSerilog ( dispose : true ) ;
41+ builder . Host . UseSerilog ( dispose : true ) ;
42+ builder . Configuration . AddEnvironmentVariables ( "GZCTF_" ) ;
5843
59- if ( string . IsNullOrWhiteSpace ( connectionString ) )
60- {
61- builder . Services . AddDistributedMemoryCache ( ) ;
44+ builder . Services . AddServiceDiscovery ( ) ;
45+ builder . Services . ConfigureHttpClientDefaults ( http =>
46+ {
47+ http . AddStandardResilienceHandler ( ) ;
48+ http . AddServiceDiscovery ( ) ;
49+ } ) ;
6250 }
63- else
51+
52+ internal void ConfigureCacheAndSignalR ( )
6453 {
65- builder . Services . AddStackExchangeRedisCache ( options =>
54+ var signalrBuilder = builder . Services . AddSignalR ( ) . AddJsonProtocol ( options =>
6655 {
67- options . Configuration = connectionString ;
56+ options . PayloadSerializerOptions . ConfigCustomSerializerOptions ( ) ;
6857 } ) ;
6958
70- signalrBuilder . AddStackExchangeRedis ( connectionString , options =>
59+ var connectionString = builder . Configuration . GetConnectionString ( "RedisCache" ) ;
60+
61+ if ( string . IsNullOrWhiteSpace ( connectionString ) )
7162 {
72- options . Configuration . ChannelPrefix = new RedisChannel ( "GZCTF" , RedisChannel . PatternMode . Literal ) ;
73- } ) ;
74- }
63+ builder . Services . AddDistributedMemoryCache ( ) ;
64+ }
65+ else
66+ {
67+ builder . Services . AddStackExchangeRedisCache ( options =>
68+ {
69+ options . Configuration = connectionString ;
70+ } ) ;
7571
76- builder . Services . AddMemoryCache ( ) ;
72+ signalrBuilder . AddStackExchangeRedis ( connectionString , options =>
73+ {
74+ options . Configuration . ChannelPrefix = new RedisChannel ( "GZCTF" , RedisChannel . PatternMode . Literal ) ;
75+ } ) ;
76+ }
77+
78+ builder . Services . AddMemoryCache ( ) ;
79+ }
7780 }
7881}
0 commit comments