Browse Source

Remove superfluous UseDeveloperExceptionPage() and AddOptions() calls

davidfowl/common-services
Reuben Bond 1 year ago
parent
commit
917764273b
10 changed files with 31 additions and 75 deletions
  1. +0
    -1
      src/ApiGateways/Mobile.Bff.Shopping/aggregator/Program.cs
  2. +1
    -7
      src/ApiGateways/Web.Bff.Shopping/aggregator/Program.cs
  3. +16
    -26
      src/Services/Ordering/Ordering.API/Program.cs
  4. +2
    -6
      src/Services/Ordering/Ordering.BackgroundTasks/Program.cs
  5. +3
    -5
      src/Services/Ordering/Ordering.SignalrHub/Program.cs
  6. +3
    -5
      src/Services/Payment/Payment.API/Program.cs
  7. +2
    -7
      src/Web/WebMVC/Program.cs
  8. +0
    -5
      src/Web/WebSPA/Program.cs
  9. +1
    -6
      src/Web/WebStatus/Program.cs
  10. +3
    -7
      src/Web/WebhookClient/Startup.cs

+ 0
- 1
src/ApiGateways/Mobile.Bff.Shopping/aggregator/Program.cs View File

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


+ 1
- 7
src/ApiGateways/Web.Bff.Shopping/aggregator/Program.cs View File

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


+ 16
- 26
src/Services/Ordering/Ordering.API/Program.cs View File

@ -40,27 +40,20 @@ builder.Services
var services = builder.Services; var services = builder.Services;
services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssemblyContaining(typeof(Program));
cfg.AddOpenBehavior(typeof(LoggingBehavior<,>));
cfg.AddOpenBehavior(typeof(ValidatorBehavior<,>));
cfg.AddOpenBehavior(typeof(TransactionBehavior<,>));
});
// Register the command validators for the validator behavior (validators based on FluentValidation library)
services.AddSingleton<IValidator<CancelOrderCommand>, CancelOrderCommandValidator>();
services.AddSingleton<IValidator<CreateOrderCommand>, CreateOrderCommandValidator>();
services.AddSingleton<IValidator<IdentifiedCommand<CreateOrderCommand, bool>>, IdentifiedCommandValidator>();
services.AddSingleton<IValidator<ShipOrderCommand>, ShipOrderCommandValidator>();
services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssemblyContaining(typeof(Program));
cfg.AddOpenBehavior(typeof(LoggingBehavior<,>));
cfg.AddOpenBehavior(typeof(ValidatorBehavior<,>));
cfg.AddOpenBehavior(typeof(TransactionBehavior<,>));
});
/*
// Build the MediatR pipeline
services.AddSingleton(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));
services.AddSingleton(typeof(IPipelineBehavior<,>), typeof(ValidatorBehavior<,>));
services.AddSingleton(typeof(IPipelineBehavior<,>), typeof(TransactionBehavior<,>));
*/
// Register the command validators for the validator behavior (validators based on FluentValidation library)
services.AddSingleton<IValidator<CancelOrderCommand>, CancelOrderCommandValidator>();
services.AddSingleton<IValidator<CreateOrderCommand>, CreateOrderCommandValidator>();
services.AddSingleton<IValidator<IdentifiedCommand<CreateOrderCommand, bool>>, IdentifiedCommandValidator>();
services.AddSingleton<IValidator<ShipOrderCommand>, ShipOrderCommandValidator>();
var queriesConnectionString = builder.Configuration["ConnectionString"]; var queriesConnectionString = builder.Configuration["ConnectionString"];
@ -78,19 +71,17 @@ services.AddSingleton<IIntegrationEventHandler<OrderStockRejectedIntegrationEven
services.AddSingleton<IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>, UserCheckoutAcceptedIntegrationEventHandler>(); services.AddSingleton<IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>, UserCheckoutAcceptedIntegrationEventHandler>();
var app = builder.Build(); var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
if (!app.Environment.IsDevelopment())
{ {
app.UseExceptionHandler("/Home/Error"); app.UseExceptionHandler("/Home/Error");
} }
var pathBase = app.Configuration["PATH_BASE"]; var pathBase = app.Configuration["PATH_BASE"];
if (!string.IsNullOrEmpty(pathBase)) if (!string.IsNullOrEmpty(pathBase))
{ {
app.UsePathBase(pathBase); app.UsePathBase(pathBase);
} }
app.UseSwagger().UseSwaggerUI(c => app.UseSwagger().UseSwaggerUI(c =>
{ {
c.SwaggerEndpoint($"{(!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty)}/swagger/v1/swagger.json", "Ordering.API V1"); 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) public static IServiceCollection AddCustomConfiguration(this IServiceCollection services, IConfiguration configuration)
{ {
services.AddOptions();
services.Configure<OrderingSettings>(configuration); services.Configure<OrderingSettings>(configuration);
services.Configure<ApiBehaviorOptions>(options => services.Configure<ApiBehaviorOptions>(options =>
{ {


+ 2
- 6
src/Services/Ordering/Ordering.BackgroundTasks/Program.cs View File

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


+ 3
- 5
src/Services/Ordering/Ordering.SignalrHub/Program.cs View File

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


+ 3
- 5
src/Services/Payment/Payment.API/Program.cs View File

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


+ 2
- 7
src/Web/WebMVC/Program.cs View File

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


+ 0
- 5
src/Web/WebSPA/Program.cs View File

@ -40,11 +40,6 @@ builder.Logging.AddAzureWebAppDiagnostics();
var app = builder.Build(); 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 // 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() // 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>(); var antiForgery = app.Services.GetRequiredService<IAntiforgery>();


+ 1
- 6
src/Web/WebStatus/Program.cs View File

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


+ 3
- 7
src/Web/WebhookClient/Startup.cs View File

@ -1,4 +1,4 @@
namespace WebhookClient;
namespace WebhookClient;
public class Startup public class Startup
{ {
@ -36,15 +36,12 @@ public class Startup
app.UsePathBase(pathBase); app.UsePathBase(pathBase);
} }
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
if (!env.IsDevelopment())
{ {
app.UseExceptionHandler("/Error"); 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. // 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 => app.Map("/check", capp =>
{ {
capp.Run(async (context) => capp.Run(async (context) =>
@ -97,7 +94,6 @@ static class ServiceExtensions
{ {
public static IServiceCollection AddConfiguration(this IServiceCollection services, IConfiguration configuration) public static IServiceCollection AddConfiguration(this IServiceCollection services, IConfiguration configuration)
{ {
services.AddOptions();
services.Configure<Settings>(configuration); services.Configure<Settings>(configuration);
return services; return services;
} }


Loading…
Cancel
Save