README.md

May 29, 2026 ยท View on GitHub

LiteBus Logo
LiteBus

A semantic, high-performance mediator for CQS and DDD in .NET. Free under MIT, forever.

Build Status Code Coverage NuGet Version Wiki

LiteBus is an in-process mediator that keeps commands, queries, and events as separate, first-class concepts so your application code stays self-documenting. It runs handlers through a typed pipeline, caches handler metadata at startup, and depends on no DI container.

  • Semantic by design. ICommand<TResult>, IQuery<TResult>, and IEvent instead of one generic request. Events can be plain POCOs.
  • Typed pipeline per message. Distinct pre-handlers, post-handlers, and error-handlers for each message type, plus open generic handlers for cross-cutting concerns.
  • Event concurrency you control. Order handlers into priority groups and run each group, and the handlers within it, sequentially or in parallel.
  • Durable when needed. An inbox schedules commands and an outbox stores integration events, with at-least-once delivery on PostgreSQL.

Install

dotnet add package LiteBus.Commands.Extensions.Microsoft.DependencyInjection
dotnet add package LiteBus.Queries.Extensions.Microsoft.DependencyInjection
dotnet add package LiteBus.Events.Extensions.Microsoft.DependencyInjection

The core messaging runtime is pulled in automatically. Install only the modules you use.

Quick start

Define a command and its handler:

public sealed record CreateProductCommand(string Name, decimal Price) : ICommand<Guid>;

public sealed class CreateProductCommandHandler : ICommandHandler<CreateProductCommand, Guid>
{
    public Task<Guid> HandleAsync(CreateProductCommand command, CancellationToken cancellationToken)
    {
        var productId = Guid.NewGuid();
        return Task.FromResult(productId);
    }
}

Register the modules and send the command:

builder.Services.AddLiteBus(liteBus =>
{
    var assembly = typeof(Program).Assembly;
    liteBus.AddCommandModule(module => module.RegisterFromAssembly(assembly));
    liteBus.AddQueryModule(module => module.RegisterFromAssembly(assembly));
    liteBus.AddEventModule(module => module.RegisterFromAssembly(assembly));
});

// Inject ICommandMediator, IQueryMediator, IEventMediator where you need them
var productId = await commandMediator.SendAsync(new CreateProductCommand("Widget", 9.99m));

Queries (IQueryMediator.QueryAsync) and events (IEventMediator.PublishAsync) follow the same shape. The Getting Started guide walks through all three end to end.

Features

FeatureWhat it doesDocs
Typed pipelinePre-, post-, and error-handlers per message type, with an ambient context shared across a single mediation.The Handler Pipeline
Handler priorityOrder handlers within a stage, and group event handlers into execution phases.Handler Priority
Tags and predicatesRun a different set of handlers per call based on runtime context.Handler Filtering
Polymorphic dispatchA handler for a base type runs for every derived message.Polymorphic Dispatch
Open generic handlersOne handler applies to every matching message; closed at startup. Ideal for logging, validation, metrics.Open Generic Handlers
Event concurrencySequential or parallel execution across priority groups and within a group.Event Module
Streaming queriesReturn IAsyncEnumerable<T> for large result sets.Query Module
Command inboxSchedule commands for reliable, out-of-band execution with idempotency keys.Command Inbox
OutboxStore integration events in the same transaction as a state change, publish after commit.Outbox
DI-agnostic coreFirst-class Microsoft DI and Autofac adapters; an adapter pattern for others.Architecture

Packages

LiteBus ships as small packages so you reference only what you run. The full layout, including abstractions and DI adapters, is in the Dependency Graph.

Full package matrix
CategoryPackage
MetapackageLiteBus
Core modulesLiteBus.Commands, LiteBus.Queries, LiteBus.Events, LiteBus.Inbox, LiteBus.Outbox, LiteBus.Messaging, LiteBus.Runtime
AbstractionsLiteBus.Commands.Abstractions, LiteBus.Queries.Abstractions, LiteBus.Events.Abstractions, LiteBus.Inbox.Abstractions, LiteBus.Outbox.Abstractions, LiteBus.Messaging.Abstractions, LiteBus.Runtime.Abstractions
PostgreSQLLiteBus.Inbox.PostgreSql, LiteBus.Outbox.PostgreSql
Microsoft DILiteBus.Extensions.Microsoft.DependencyInjection, LiteBus.Commands.Extensions.Microsoft.DependencyInjection, LiteBus.Queries.Extensions.Microsoft.DependencyInjection, LiteBus.Events.Extensions.Microsoft.DependencyInjection, LiteBus.Messaging.Extensions.Microsoft.DependencyInjection, LiteBus.Runtime.Extensions.Microsoft.DependencyInjection
Microsoft HostingLiteBus.Inbox.Extensions.Microsoft.Hosting, LiteBus.Outbox.Extensions.Microsoft.Hosting
AutofacLiteBus.Commands.Extensions.Autofac, LiteBus.Queries.Extensions.Autofac, LiteBus.Events.Extensions.Autofac, LiteBus.Messaging.Extensions.Autofac, LiteBus.Runtime.Extensions.Autofac

Coming from MediatR

MediatRLiteBus
IRequest<TResponse>ICommand<TResult> (writes) or IQuery<TResult> (reads)
IRequestICommand
INotificationIEvent, or any POCO, no interface required
IStreamRequest<TResponse>IStreamQuery<TResult> returning IAsyncEnumerable<TResult>
IPipelineBehavior<,>Typed pre-, post-, and error-handlers per message type, plus open generic handlers

See LiteBus vs. MediatR for the full comparison and migration notes.

Documentation

The LiteBus Wiki is the complete reference: concepts, per-module guides, reliable messaging, internals, troubleshooting, and a glossary.

License

LiteBus is free and licensed under the MIT License, and always will be. Contributions are welcome; see Contributing.