Skip to content

Commit e123a77

Browse files
Merge pull request #1675 from TransactionProcessing/copilot/fix-startup-configure-complexity
Reduce `Startup.Configure` complexity by extracting pipeline helpers
2 parents f64a661 + 8cd88c5 commit e123a77

1 file changed

Lines changed: 44 additions & 37 deletions

File tree

TransactionProcessor/Startup.cs

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ public void Configure(IApplicationBuilder app,
111111
Logger.Initialise(logger);
112112

113113
Startup.Configuration.LogConfiguration(Logger.LogWarning);
114-
115-
foreach (KeyValuePair<Type, String> type in TypeMap.Map) {
116-
Logger.LogInformation($"Type name {type.Value} mapped to {type.Key.Name}");
117-
}
114+
this.LogTypeMappings();
118115
app.UseMiddleware<TenantMiddleware>();
119116
app.AddRequestResponseLogging();
120117
app.AddExceptionHandler();
@@ -125,44 +122,14 @@ public void Configure(IApplicationBuilder app,
125122
app.UseAuthorization();
126123
app.UseMetricServer(s => {
127124
});
128-
app.UseEndpoints(endpoints => {
129-
endpoints.MapControllers();
130-
endpoints.MapHealthChecks("health",
131-
new HealthCheckOptions {
132-
Predicate = _ => true,
133-
ResponseWriter = Shared.HealthChecks.HealthCheckMiddleware.WriteResponse
134-
});
135-
endpoints.MapHealthChecks("healthui",
136-
new HealthCheckOptions
137-
{
138-
Predicate = _ => true,
139-
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
140-
});
141-
endpoints.MapEstateEndpoints();
142-
endpoints.MapMerchantEndpoints();
143-
endpoints.MapContractEndpoints();
144-
endpoints.MapOperatorEndpoints();
145-
endpoints.MapFloatEndpoints();
146-
endpoints.MapVoucherEndpoints();
147-
endpoints.MapTransactionEndpoints();
148-
endpoints.MapSettlementEndpoints();
149-
});
125+
this.ConfigureEndpoints(app);
150126

151127
app.UseSwagger();
152128

153129
app.UseSwaggerUI();
154130

155131
app.PreWarm();
156-
157-
var loadedTokensAssemblies = AppDomain.CurrentDomain
158-
.GetAssemblies()
159-
.Where(a => a.GetName().Name == "Microsoft.IdentityModel.Tokens")
160-
.ToList();
161-
162-
foreach (var asm in loadedTokensAssemblies)
163-
{
164-
Console.WriteLine($"[Trace] Tokens Assembly: {asm.Location} — Version: {asm.GetName().Version}");
165-
}
132+
this.TraceLoadedTokenAssemblies();
166133
}
167134

168135
public void ConfigureContainer(ServiceRegistry services) {
@@ -186,7 +153,47 @@ public void ConfigureContainer(ServiceRegistry services) {
186153

187154
Startup.ServiceProvider = services.BuildServiceProvider();
188155
}
156+
157+
private void ConfigureEndpoints(IApplicationBuilder app) {
158+
app.UseEndpoints(endpoints => {
159+
endpoints.MapControllers();
160+
endpoints.MapHealthChecks("health",
161+
new HealthCheckOptions {
162+
Predicate = _ => true,
163+
ResponseWriter = Shared.HealthChecks.HealthCheckMiddleware.WriteResponse
164+
});
165+
endpoints.MapHealthChecks("healthui",
166+
new HealthCheckOptions {
167+
Predicate = _ => true,
168+
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
169+
});
170+
endpoints.MapEstateEndpoints();
171+
endpoints.MapMerchantEndpoints();
172+
endpoints.MapContractEndpoints();
173+
endpoints.MapOperatorEndpoints();
174+
endpoints.MapFloatEndpoints();
175+
endpoints.MapVoucherEndpoints();
176+
endpoints.MapTransactionEndpoints();
177+
endpoints.MapSettlementEndpoints();
178+
});
179+
}
180+
181+
private void LogTypeMappings() {
182+
foreach (KeyValuePair<Type, String> type in TypeMap.Map) {
183+
Logger.LogInformation($"Type name {type.Value} mapped to {type.Key.Name}");
184+
}
185+
}
186+
187+
private void TraceLoadedTokenAssemblies() {
188+
List<Assembly> loadedTokensAssemblies = AppDomain.CurrentDomain.GetAssemblies()
189+
.Where(a => a.GetName().Name == "Microsoft.IdentityModel.Tokens")
190+
.ToList();
191+
192+
foreach (Assembly asm in loadedTokensAssemblies) {
193+
Console.WriteLine($"[Trace] Tokens Assembly: {asm.Location} - Version: {asm.GetName().Version}");
194+
}
195+
}
189196
}
190197

191198
#endregion
192-
}
199+
}

0 commit comments

Comments
 (0)