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>, andIEventinstead 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.
dotnet add package LiteBus.Commands.Extensions.Microsoft.DependencyInjection
dotnet add package LiteBus.Queries.Extensions.Microsoft.DependencyInjection
dotnet add package LiteBus.Events.Extensions.Microsoft.DependencyInjectionThe core messaging runtime is pulled in automatically. Install only the modules you use.
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.
| Feature | What it does | Docs |
|---|---|---|
| Typed pipeline | Pre-, post-, and error-handlers per message type, with an ambient context shared across a single mediation. | The Handler Pipeline |
| Handler priority | Order handlers within a stage, and group event handlers into execution phases. | Handler Priority |
| Tags and predicates | Run a different set of handlers per call based on runtime context. | Handler Filtering |
| Polymorphic dispatch | A handler for a base type runs for every derived message. | Polymorphic Dispatch |
| Open generic handlers | One handler applies to every matching message; closed at startup. Ideal for logging, validation, metrics. | Open Generic Handlers |
| Event concurrency | Sequential or parallel execution across priority groups and within a group. | Event Module |
| Streaming queries | Return IAsyncEnumerable<T> for large result sets. |
Query Module |
| Command inbox | Schedule commands for reliable, out-of-band execution with idempotency keys. | Command Inbox |
| Outbox | Store integration events in the same transaction as a state change, publish after commit. | Outbox |
| DI-agnostic core | First-class Microsoft DI and Autofac adapters; an adapter pattern for others. | Architecture |
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
| Category | Package |
|---|---|
| Metapackage | LiteBus |
| Core modules | LiteBus.Commands, LiteBus.Queries, LiteBus.Events, LiteBus.Inbox, LiteBus.Outbox, LiteBus.Messaging, LiteBus.Runtime |
| Abstractions | LiteBus.Commands.Abstractions, LiteBus.Queries.Abstractions, LiteBus.Events.Abstractions, LiteBus.Inbox.Abstractions, LiteBus.Outbox.Abstractions, LiteBus.Messaging.Abstractions, LiteBus.Runtime.Abstractions |
| PostgreSQL | LiteBus.Inbox.PostgreSql, LiteBus.Outbox.PostgreSql |
| Microsoft DI | LiteBus.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 Hosting | LiteBus.Inbox.Extensions.Microsoft.Hosting, LiteBus.Outbox.Extensions.Microsoft.Hosting |
| Autofac | LiteBus.Commands.Extensions.Autofac, LiteBus.Queries.Extensions.Autofac, LiteBus.Events.Extensions.Autofac, LiteBus.Messaging.Extensions.Autofac, LiteBus.Runtime.Extensions.Autofac |
| MediatR | LiteBus |
|---|---|
IRequest<TResponse> |
ICommand<TResult> (writes) or IQuery<TResult> (reads) |
IRequest |
ICommand |
INotification |
IEvent, 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.
The LiteBus Wiki is the complete reference: concepts, per-module guides, reliable messaging, internals, troubleshooting, and a glossary.
LiteBus is free and licensed under the MIT License, and always will be. Contributions are welcome; see Contributing.