Routya

High-Performance
Message Dispatching

Fast, lightweight CQRS library built for .NET applications. Competitive with MediatR while offering more flexibility and control.

v3.0.1
6.2k installs
.NET 8, 9, 10
30% Faster
dotnet add package Routya.Core
For peak performance, also install the source generator
dotnet add package Routya.SourceGenerators

Built for Performance

Everything you need for high-performance CQRS message dispatching in modern .NET applications

Blazing Fast

High-performance dispatching with registry-based optimization. 30% faster than MediatR for notifications with Singleton handlers.

Configurable Lifetimes

Choose Singleton, Scoped, or Transient per handler. Optimize for your specific use case with flexible lifetime management.

Pipeline Behaviors

Optional cross-cutting concerns support. Add logging, validation, and custom behaviors that execute around your requests.

CQRS Pattern

Clean interface-based abstraction for Requests/Responses and Notifications. Minimal overhead with maximum clarity.

Parallel & Sequential

Supports both sequential and parallel notification dispatching. Choose the right strategy for your scenario.

Memory Efficient

Zero memory leaks with proper scope management. 56% less memory than MediatR for Singleton notification handlers.

Proven Performance

Benchmarked against MediatR 13.1.0 using BenchmarkDotNet on .NET 8

11th Gen Intel Core i7-11800H @ 2.30GHz.NET 8.0.17Windows 11

Request Dispatching

Execution time in nanoseconds

MediatR SendAsyncBaseline
356.3 ns
1016 B0%
Routya SingletonCompetitive
377.8 ns
1008 B+6%
Routya TransientCompetitive
397.0 ns
1032 B+11%
Routya Scoped
427.0 ns
1216 B+20%
Routya Singleton Async
436.8 ns
1168 B+23%
Routya Transient Async
450.2 ns
1192 B+26%
Routya Scoped Async
495.0 ns
1376 B+39%

Notification Dispatching

Execution time in nanoseconds

MediatR PublishBaseline
157.6 ns
440 B0%
Routya Singleton SequentialWinner
110.5 ns
192 B-30%
Routya Singleton Parallel9% Faster
143.6 ns
312 B-9%
Routya Transient Sequential7% Faster
146.0 ns
240 B-7%
Routya Transient Parallel
170.6 ns
360 B+8%
Routya Scoped Sequential
238.1 ns
424 B+51%
Routya Scoped Parallel
265.8 ns
544 B+69%
30%
Faster notification dispatching with Singleton Sequential handlers
56%
Less memory allocation for Singleton notification handlers
7%
Faster notifications with Transient Sequential handlers - maximum isolation with performance

Documentation

Everything you need to get started with Routya in your .NET applications

Quick Start Guide

Installation

dotnet add package Routya.Core

For peak performance, install the source generator — it emits compile-time handler registrations and eliminates reflection overhead at runtime.

dotnet add package Routya.SourceGenerators

Register Services

// Register with assembly scanning
builder.Services.AddRoutya(
    cfg => cfg.Scope = RoutyaDispatchScope.Scoped,
    Assembly.GetExecutingAssembly()
);

Define a Request

public class HelloRequest(string name) : IRequest<string>
{
    public string Name { get; } = name;
}

Create a Handler

public class HelloHandler : IAsyncRequestHandler<HelloRequest, string>
{
    public async Task<string> HandleAsync(
        HelloRequest request,
        CancellationToken cancellationToken)
    {
        return await Task.FromResult($"Hello, {request.Name}!");
    }
}

Dispatch the Request

var result = await _dispatcher.SendAsync<HelloRequest, string>(
    new HelloRequest("World")
);