using FinancialApi; using FinancialApi.Application; using FinancialApi.Infrastructure; using FinancialApi.ServiceDefaults; using JasperFx.CodeGeneration; using JasperFx.Resources; using Microsoft.EntityFrameworkCore; using Wolverine; using Wolverine.EntityFrameworkCore; using Wolverine.Sqlite; var builder = WebApplication.CreateBuilder(args); builder.Services.AddExceptionHandler(); builder.Services.AddProblemDetails(); var connectionString = "Data Source=demo.db"; builder.Services.AddDbContext(options => options.UseSqlite(connectionString)); builder.Services.AddScoped(); // Add services to the container. // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi builder.Services.AddOpenApi(); builder.AddServiceDefaults(); builder.Host.UseWolverine(opts => { opts.Discovery.IncludeAssembly(typeof(ApplyFeeHandler).Assembly); opts.PersistMessagesWithSqlite(connectionString); opts.UseEntityFrameworkCoreTransactions(); opts.Policies.AutoApplyTransactions(); }); builder.Host.UseResourceSetupOnStartup(); var app = builder.Build(); app.UseExceptionHandler(); using (var scope = app.Services.CreateScope()) { var db = scope.ServiceProvider.GetRequiredService(); await db.Database.MigrateAsync(); } // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.MapOpenApi(); } app.UseHttpsRedirection(); app.MapPost("/accounts/apply-fee", async (ApplyFeeCommand cmd, IMessageBus bus) => { await bus.InvokeAsync(cmd); return Results.Accepted(); }); app.MapPost("/accounts/transfer", async (TransferFundsCommand cmd, IMessageBus bus) => { await bus.InvokeAsync(cmd); return Results.Accepted(); }); app.Run();