Browse Source

More defaults

davidfowl/common-services
David Fowler 1 year ago
committed by Reuben Bond
parent
commit
00fc3d8a65
2 changed files with 7 additions and 29 deletions
  1. +2
    -29
      src/Services/Basket/Basket.API/Program.cs
  2. +5
    -0
      src/Services/Services.Common/CommonExtensions.cs

+ 2
- 29
src/Services/Basket/Basket.API/Program.cs View File

@ -2,9 +2,7 @@
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddKeyVault();
builder.Services.AddApplicationInsights(builder.Configuration);
builder.AddServiceDefaults();
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.UseExceptionHandler("/Home/Error");
}
var pathBase = app.Configuration["PATH_BASE"];
if (!string.IsNullOrEmpty(pathBase))
{
app.UsePathBase(pathBase);
}
app.UseDefaultOpenApi(builder.Configuration);
app.UseServiceDefaults();
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>();


+ 5
- 0
src/Services/Services.Common/CommonExtensions.cs 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))


Loading…
Cancel
Save