Files
silver-octo-spoon/wolverine/a-frame-architecture/FinancialApi/Program.cs
T

63 lines
1.5 KiB
C#

using FinancialApi;
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);
var connectionString = "Data Source=demo.db";
builder.Services.AddDbContext<AccountDbContext>(options =>
options.UseSqlite(connectionString));
// 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();
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<AccountDbContext>();
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();