Remove superfluous UseDeveloperExceptionPage() and AddOptions() calls

This commit is contained in:
Reuben Bond 2023-05-04 14:05:47 -07:00
parent e2d8590a26
commit 917764273b
10 changed files with 31 additions and 75 deletions

View File

@ -15,7 +15,6 @@ builder.Services.AddControllers()
builder.Services.AddSwaggerGen(options =>
{
//options.DescribeAllEnumsAsStrings();
options.SwaggerDoc("v1", new OpenApiInfo
{
Title = "Shopping Aggregator for Mobile Clients",

View File

@ -1,6 +1,5 @@
var builder = WebApplication.CreateBuilder(args);
builder.Logging.AddConsole();
builder.Services.AddHealthChecks()
.AddCheck("self", () => HealthCheckResult.Healthy())
.AddUrlGroup(new Uri(builder.Configuration["CatalogUrlHC"]), name: "catalogapi-check", tags: new string[] { "catalogapi" })
@ -13,11 +12,7 @@ builder.Services.AddCustomMvc(builder.Configuration)
.AddApplicationServices()
.AddGrpcServices();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
}
@ -82,7 +77,6 @@ public static class ServiceCollectionExtensions
}
public static IServiceCollection AddCustomMvc(this IServiceCollection services, IConfiguration configuration)
{
services.AddOptions();
services.Configure<UrlsConfig>(configuration.GetSection("urls"));
services.AddControllers()

View File

@ -55,13 +55,6 @@ var services = builder.Services;
services.AddSingleton<IValidator<IdentifiedCommand<CreateOrderCommand, bool>>, IdentifiedCommandValidator>();
services.AddSingleton<IValidator<ShipOrderCommand>, ShipOrderCommandValidator>();
/*
// Build the MediatR pipeline
services.AddSingleton(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));
services.AddSingleton(typeof(IPipelineBehavior<,>), typeof(ValidatorBehavior<,>));
services.AddSingleton(typeof(IPipelineBehavior<,>), typeof(TransactionBehavior<,>));
*/
var queriesConnectionString = builder.Configuration["ConnectionString"];
services.AddScoped<IOrderQueries>(sp => new OrderQueries(queriesConnectionString));
@ -78,19 +71,17 @@ services.AddSingleton<IIntegrationEventHandler<OrderStockRejectedIntegrationEven
services.AddSingleton<IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>, UserCheckoutAcceptedIntegrationEventHandler>();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
}
var pathBase = app.Configuration["PATH_BASE"];
if (!string.IsNullOrEmpty(pathBase))
{
app.UsePathBase(pathBase);
}
app.UseSwagger().UseSwaggerUI(c =>
{
c.SwaggerEndpoint($"{(!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty)}/swagger/v1/swagger.json", "Ordering.API V1");
@ -336,7 +327,6 @@ static class CustomExtensionsMethods
public static IServiceCollection AddCustomConfiguration(this IServiceCollection services, IConfiguration configuration)
{
services.AddOptions();
services.Configure<OrderingSettings>(configuration);
services.Configure<ApiBehaviorOptions>(options =>
{

View File

@ -9,18 +9,14 @@ builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.Environment
builder.Configuration.AddEnvironmentVariables();
builder.Services.AddCustomHealthCheck(builder.Configuration)
.Configure<BackgroundTaskSettings>(builder.Configuration)
.AddOptions()
.AddHostedService<GracePeriodManagerService>()
.AddEventBus(builder.Configuration);
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
}
app.UseRouting();
app.MapHealthChecks("/hc", new HealthCheckOptions()

View File

@ -85,19 +85,17 @@ builder.Services.AddSingleton<IIntegrationEventHandler<OrderStatusChangedToStock
builder.Services.AddSingleton<IIntegrationEventHandler<OrderStatusChangedToSubmittedIntegrationEvent>, OrderStatusChangedToSubmittedIntegrationEventHandler>();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
}
var pathBase = builder.Configuration["PATH_BASE"];
if (!string.IsNullOrEmpty(pathBase))
{
app.UsePathBase(pathBase);
}
app.UseRouting();
app.UseCors("CorsPolicy");
app.UseAuthentication();

View File

@ -57,19 +57,17 @@ else
}
RegisterEventBus(builder.Services);
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
}
var pathBase = app.Configuration["PATH_BASE"];
if (!string.IsNullOrEmpty(pathBase))
{
app.UsePathBase(pathBase);
}
ConfigureEventBus(app);
app.UseRouting();

View File

@ -12,11 +12,7 @@ builder.WebHost.CaptureStartupErrors(false);
var app = builder.Build();
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub");
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
}
@ -72,8 +68,7 @@ static void AddHealthChecks(WebApplicationBuilder builder)
static void AddCustomMvc(WebApplicationBuilder builder)
{
builder.Services.AddOptions()
.Configure<AppSettings>(builder.Configuration)
builder.Services.Configure<AppSettings>(builder.Configuration)
.AddSession()
.AddDistributedMemoryCache();

View File

@ -40,11 +40,6 @@ builder.Logging.AddAzureWebAppDiagnostics();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
// Here we add Angular default Anti-forgery cookie name on first load. https://angular.io/guide/http#security-xsrf-protection
// This cookie will be read by Angular app and its value will be sent back to the application as the header configured in .AddAntiforgery()
var antiForgery = app.Services.GetRequiredService<IAntiforgery>();

View File

@ -12,7 +12,6 @@ builder.WebHost.CaptureStartupErrors(false);
builder.Services.AddApplicationInsightsTelemetry(builder.Configuration);
builder.Services.AddApplicationInsightsKubernetesEnricher();
builder.Services.AddMvc();
builder.Services.AddOptions();
builder.Services.AddHealthChecks()
.AddCheck("self", () => HealthCheckResult.Healthy());
builder.Services
@ -21,11 +20,7 @@ builder.Services
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
}

View File

@ -1,4 +1,4 @@
namespace WebhookClient;
namespace WebhookClient;
public class Startup
{
@ -36,15 +36,12 @@ public class Startup
app.UsePathBase(pathBase);
}
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
if (!env.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
}
app.Map("/check", capp =>
{
capp.Run(async (context) =>
@ -97,7 +94,6 @@ static class ServiceExtensions
{
public static IServiceCollection AddConfiguration(this IServiceCollection services, IConfiguration configuration)
{
services.AddOptions();
services.Configure<Settings>(configuration);
return services;
}