using LevadS;
var builder = WebApplication.CreateBuilder(args);
/* ... */
builder.Services.AddLevadS(b => b
.AddRequestHandler<WeatherRequest, WeatherResponse>(
"current:{city:string}",
(string city) => new WeatherResponse
(
city,
DateOnly.FromDateTime(DateTime.Now),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
)
)
);
var app = builder.Build();
app.MapGet(
"/weatherResponse/{city}",
async (IDispatcher dispatcher, string city)
=> await dispatcher.RequestAsync(new WeatherRequest(), $"current:{city}")
);
app.Run();
LevadS (pronounced "levadas") is a lightweight mediator library for .NET, designed to facilitate message-based, topic-driven communication within applications. It enables developers to implement the Mediator pattern, promoting loose coupling and separation of concerns by allowing different parts of an application to communicate through messages without direct dependencies.
Topics, concept known from multiple message brokers, are first-class citizens in LevadS. They enable more granular control over message routing and handling. However, they are completely optional and can be used at the developer's discretion.
LevadS comes with minimal dependencies, is designed for easy integration and follows modern patterns (notably Minimal APIs' way of registration).
Supports .NET 8.0+.