-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathProgram.cs
More file actions
41 lines (32 loc) · 1.23 KB
/
Program.cs
File metadata and controls
41 lines (32 loc) · 1.23 KB
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
using OpenSleigh.DependencyInjection;
using OpenSleigh.InMemory;
using OpenSleigh.Reporting;
using OpenSleigh.Samples.PizzaTracker;
using OpenSleigh.Transport;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenSleigh(cfg =>
{
cfg.UseInMemoryTransport()
.UseInMemoryPersistence()
.AddSaga<OrderSaga, OrderState>();
});
builder.Services.AddOpenSleighReporting();
var app = builder.Build();
// OpenSleigh reporting endpoints + OpenAPI document at /openapi/v1.json
app.MapOpenSleighReporting();
// POST /orders — place a new pizza order
app.MapPost("/orders", async (PlaceOrderRequest request, IMessageBus bus) =>
{
var message = new PlaceOrder(request.CustomerName, request.PizzaType);
await bus.PublishAsync(message);
return Results.Accepted(value: new
{
Message = $"Order placed! {request.PizzaType} for {request.CustomerName}.",
Tip = "Use GET /opensleigh/sagas to track all orders, or GET /opensleigh/sagas/{instanceId} for a specific order."
});
})
.WithTags("Orders")
.WithSummary("Place a pizza order")
.WithDescription("Publishes a PlaceOrder message that starts the OrderSaga.");
app.Run();
public record PlaceOrderRequest(string CustomerName, string PizzaType);