Quick start
Three steps from an empty project to a working dispatch.
-
Install (in the project that contains
Program.cs):Terminal window dotnet add package Vitreousdotnet add package Vitreous.SourceGeneration -
Define a message and its handler anywhere in your project:
using Vitreous;using Vitreous.Abstractions;public sealed record CreateOrderCommand(string Customer) : ICommand<Guid>;public sealed class CreateOrderHandler : ICommandHandler<CreateOrderCommand, Guid>{public ValueTask<Result<Guid>> Handle(CreateOrderCommand command, CancellationToken ct = default){if (string.IsNullOrWhiteSpace(command.Customer))return new(Error.Validation("Customer is required."));return new(Guid.NewGuid()); // T converts to Result<T> implicitly}} -
Register and dispatch:
var builder = WebApplication.CreateBuilder(args);builder.Services.AddVitreousHandlers(); // generated at build time — finds every handlervar app = builder.Build();app.MapPost("/orders", async (CreateOrderCommand cmd, ISender sender, CancellationToken ct) =>{var result = await sender.Send(cmd, ct);return result.Match(id => Results.Created($"/orders/{id}", new { id }),err => Results.BadRequest(new { err.Code, err.Message }));});app.Run();
That’s it. No attributes, no assembly scanning, and the compiler warns you (VIT001) if a command or query has no handler.
Next, build your first feature step by step.