/
Program.cs
67 lines (52 loc) · 2.02 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using AppWithMiddleware;
using IntegrationTests;
using JasperFx.Core;
using Marten;
using Oakton;
using Oakton.Resources;
using Wolverine;
using Wolverine.Attributes;
using Wolverine.FluentValidation;
using Wolverine.Marten;
using Wolverine.RabbitMQ;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
// Just letting Marten build out known database schema elements upfront
// Helps with Wolverine integration in development
builder.Services.AddResourceSetupOnStartup();
builder.Services.AddMarten(opts =>
{
// This would be from your configuration file in typical usage
opts.Connection(Servers.PostgresConnectionString);
opts.DatabaseSchemaName = "wolverine_middleware";
})
// This is the wolverine integration for the outbox/inbox,
// transactional middleware, saga persistence we don't care about
// yet
.IntegrateWithWolverine();
#region sample_registering_middleware_by_message_type
builder.Host.UseWolverine(opts =>
{
// This middleware should be applied to all handlers where the
// command type implements the IAccountCommand interface that is the
// "detected" message type of the middleware
opts.Policies.ForMessagesOfType<IAccountCommand>().AddMiddleware(typeof(AccountLookupMiddleware));
opts.UseFluentValidation();
// Explicit routing for the AccountUpdated
// message handling. This has precedence over conventional routing
opts.PublishMessage<AccountUpdated>()
.ToLocalQueue("signalr")
// Throw the message away if it's not successfully
// delivered within 10 seconds
.DeliverWithin(10.Seconds())
// Not durable
.BufferedInMemory();
});
#endregion
var app = builder.Build();
app.MapControllers();
// One Minimal API that just delegates directly to Wolverine
app.MapPost("/accounts/debit", (DebitAccount command, IMessageBus bus) => bus.InvokeAsync(command));
// This is important, I'm opting into Oakton to be my
// command line executor for extended options
return await app.RunOaktonCommands(args);