2023-05-02 21:22:06 -07:00

61 lines
1.7 KiB
C#

using Services.Common;
var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults();
builder.Services.AddGrpc(options =>
{
options.EnableDetailedErrors = true;
});
builder.Services.AddControllers(options =>
{
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
options.Filters.Add(typeof(ValidateModelStateFilter));
});
builder.Services.AddRedis(builder.Configuration);
builder.Services.AddTransient<ProductPriceChangedIntegrationEventHandler>();
builder.Services.AddTransient<OrderStartedIntegrationEventHandler>();
builder.Services.AddTransient<IBasketRepository, RedisBasketRepository>();
builder.Services.AddTransient<IIdentityService, IdentityService>();
var app = builder.Build();
app.MapGet("/", () => Results.Redirect("/swagger"));
app.UseServiceDefaults();
app.MapGrpcService<BasketService>();
app.MapControllers();
var eventBus = app.Services.GetRequiredService<IEventBus>();
eventBus.Subscribe<ProductPriceChangedIntegrationEvent, ProductPriceChangedIntegrationEventHandler>();
eventBus.Subscribe<OrderStartedIntegrationEvent, OrderStartedIntegrationEventHandler>();
try
{
app.Logger.LogInformation("Configuring web host ({ApplicationContext})...", AppName);
app.Logger.LogInformation("Starting web host ({ApplicationContext})...", AppName);
await app.RunAsync();
return 0;
}
catch (Exception ex)
{
app.Logger.LogCritical(ex, "Program terminated unexpectedly ({ApplicationContext})!", AppName);
return 1;
}
public partial class Program
{
private static string Namespace = typeof(Program).Assembly.GetName().Name;
public static string AppName = Namespace.Substring(Namespace.LastIndexOf('.', Namespace.LastIndexOf('.') - 1) + 1);
}