Vitreous.Templates 0.6.0

dotnet new install Vitreous.Templates@0.6.0
                    
This package contains a .NET Template Package you can call from the shell/command line.

Vitreous

Vitreous Downloads

SourceGeneration DevUI Caching Caching.Redis FluentValidation Templates Docs

A high-performance, source-generated mediator for .NET — a modern alternative to MediatR with zero runtime reflection, first-class caching, and a built-in developer UI. Supports .NET 8, 9, 10 and 11.

Documentation: domduva.github.io/Vitreous — guides, concepts, the API reference and a step-by-step tutorial.

Packages

Package Purpose Docs
Vitreous Core mediator: commands, queries, notifications, pipeline behaviors, Result type Concepts
Vitreous.SourceGeneration Roslyn incremental generator — eliminates all runtime reflection Source generator
Vitreous.DevUI Embedded developer dashboard: live traces, logs, cache hit indicators Developer UI
Vitreous.Caching Pipeline behaviors for IDistributedCache-backed query caching Caching
Vitreous.Caching.Redis Redis backend with tag-based bulk invalidation Caching
Vitreous.FluentValidation Pipeline behaviors that run FluentValidation validators before the handler Validation
Vitreous.Templates dotnet new templates for new projects, and for the messages and behaviors you add to them Project templates

Quick start

Three steps from an empty project to a working dispatch.

1. Install (in the project that contains Program.cs):

dotnet add package Vitreous
dotnet add package Vitreous.SourceGeneration

2. 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
    }
}

3. Register and dispatch:

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddVitreousHandlers(); // generated at build time — finds every handler

var 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.

Starting a new project? The templates create one with all of this already set up.

No source generator? Call AddVitreousHandlers(typeof(Program).Assembly) instead and handlers are discovered by reflection at startup. See Registration methods.


Templates

dotnet new install Vitreous.Templates
dotnet new vitreous-api -n Shop
Template Creates
vitreous-api A minimal API in vertical slices
vitreous-console A command-line app in vertical slices
vitreous-worker A background service in vertical slices
vitreous-clean A layered solution (Domain, Application, Infrastructure) with a host: --host api, console or worker
vitreous-command, vitreous-query, vitreous-notification, vitreous-behavior A message and its handler, or a pipeline behavior, in an existing project

Every project template takes -f net8.0 to net11.0, --validation and --tests. Most also take --caching none|memory|redis, and vitreous-api takes --aot. Start with vertical slices; pick vitreous-clean when you have business rules to keep apart from the database and the app around them. See Project templates for every option and what is in each project.


Performance

Dispatch against MediatR on .NET 11.0.0 (Intel Xeon Silver 4114, 2.2 GHz). Source: benchmark/Vitreous.Benchmarks.

Scenario MediatR Vitreous
Send query 159.2 ns / 192 B 102.0 ns / 0 B
Send query (200+ handlers registered) 146.9 ns / 192 B 109.1 ns / 0 B
Send void command 166.6 ns / 120 B 86.9 ns / 0 B
Publish notification 224.0 ns / 272 B 194.4 ns / 0 B
Send query (+ 1 behavior) 319.6 ns / 368 B 128.2 ns / 56 B
Stream query (1 item) 401.5 ns / 496 B 186.2 ns / 120 B
Stream query (10 items) 898.9 ns / 496 B 434.5 ns / 120 B

Dispatch is one lookup on the message's concrete type, so its cost does not grow with the number of registered handlers.

Startup with 200+ handlers registered is ~150× faster and allocates ~50× less than MediatR, because AddVitreousHandlers() emits direct registration calls at build time. Full results and how to run them: Performance.


Documentation

Everything lives on the documentation site.

Getting started

  • Installation — the packages, which ones you need, and how to register them
  • Quick start — three steps from an empty project to a working dispatch
  • Build your first feature — a tutorial: command, query, pipeline behavior and endpoints

Concepts

Guides

Reference


License

MIT

  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.6.0 93 11/24/2026