Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fast-endpoints: trigger event from anywhere
global using FastEndpoints;
var builder = WebApplication.CreateBuilder();
builder.Services.AddFastEndpoints();
var app = builder.Build();
app.UseAuthorization();
app.UseFastEndpoints();
Task.Run(async () =>
{
await Task.Delay(1000);
await Event<OrderCreatedEvent>.PublishAsync(new()
{
OrderID = "001",
CustomerName = "customer name",
OrderTotal = 1234.56m
});
});
app.Run();
public class OrderCreatedEvent
{
public string OrderID { get; set; }
public string CustomerName { get; set; }
public decimal OrderTotal { get; set; }
}
public class OrderCreationHandler : FastEventHandler<OrderCreatedEvent>
{
public override Task HandleAsync(OrderCreatedEvent eventModel, CancellationToken ct)
{
var logger = Resolve<ILogger<OrderCreationHandler>>();
logger.LogInformation($"order created event received:[{eventModel.OrderID}]");
return Task.CompletedTask;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment