More defaults

This commit is contained in:
David Fowler 2023-05-02 08:11:55 -07:00 committed by Reuben Bond
parent 9af6d6342d
commit 00fc3d8a65
2 changed files with 7 additions and 29 deletions

View File

@ -2,9 +2,7 @@
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddKeyVault(); builder.AddServiceDefaults();
builder.Services.AddApplicationInsights(builder.Configuration);
builder.Services.AddGrpc(options => builder.Services.AddGrpc(options =>
{ {
@ -17,24 +15,12 @@ builder.Services.AddControllers(options =>
options.Filters.Add(typeof(ValidateModelStateFilter)); options.Filters.Add(typeof(ValidateModelStateFilter));
}); });
builder.Services.AddDefaultOpenApi(builder.Configuration);
builder.Services.AddDefaultAuthentication(builder.Configuration);
builder.Services.AddDefaultHealthChecks(builder.Configuration);
builder.Host.UseDefaultSerilog(builder.Configuration, AppName);
builder.WebHost.UseDefaultPorts(builder.Configuration);
builder.WebHost.UseFailing(options => builder.WebHost.UseFailing(options =>
{ {
options.ConfigPath = "/Failing"; options.ConfigPath = "/Failing";
options.NotFilteredPaths.AddRange(new[] { "/hc", "/liveness" }); options.NotFilteredPaths.AddRange(new[] { "/hc", "/liveness" });
}); });
builder.Services.AddEventBus(builder.Configuration);
builder.Services.Configure<BasketSettings>(builder.Configuration); builder.Services.Configure<BasketSettings>(builder.Configuration);
builder.Services.AddRedis(); builder.Services.AddRedis();
@ -49,24 +35,11 @@ var app = builder.Build();
app.MapGet("hello", () => "hello"); app.MapGet("hello", () => "hello");
if (!app.Environment.IsDevelopment()) app.UseServiceDefaults();
{
app.UseExceptionHandler("/Home/Error");
}
var pathBase = app.Configuration["PATH_BASE"];
if (!string.IsNullOrEmpty(pathBase))
{
app.UsePathBase(pathBase);
}
app.UseDefaultOpenApi(builder.Configuration);
app.MapGrpcService<BasketService>(); app.MapGrpcService<BasketService>();
app.MapControllers(); app.MapControllers();
app.MapDefaultHealthChecks();
var eventBus = app.Services.GetRequiredService<IEventBus>(); var eventBus = app.Services.GetRequiredService<IEventBus>();
eventBus.Subscribe<ProductPriceChangedIntegrationEvent, ProductPriceChangedIntegrationEventHandler>(); eventBus.Subscribe<ProductPriceChangedIntegrationEvent, ProductPriceChangedIntegrationEventHandler>();

View File

@ -58,6 +58,11 @@ public static class CommonExtensions
public static WebApplication UseServiceDefaults(this WebApplication app) public static WebApplication UseServiceDefaults(this WebApplication app)
{ {
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
}
var pathBase = app.Configuration["PATH_BASE"]; var pathBase = app.Configuration["PATH_BASE"];
if (!string.IsNullOrEmpty(pathBase)) if (!string.IsNullOrEmpty(pathBase))