Skip to content

sierrastack/SierraStack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build NuGet NuGet NuGet License: MIT

SierraStack.Mediator

SierraStack.Mediator is a lightweight, extensible in-process mediator for .NET. It provides a clean way to handle request/response messaging, supports pipeline behaviors, and is designed to be a modern, open-source alternative to MediatR — built for performance, simplicity, and testability.


💬 We're actively working on v0.2.0 and want your input!
📌 Join the conversation in this pinned issue
Let us know what you'd love to see next.

✨ Features

  • ✅ Request/Response messaging with IRequest<TResponse> and IRequestHandler<TRequest, TResponse>
  • ✅ In-process event publishing via INotification
  • ✅ Built-in pipeline behaviors for:
    • Logging
    • Validation (FluentValidation + Custom Abstraction)
    • Retry (Polly)
    • Caching
    • Performance measurement
    • Exception handling
  • ✅ Zero external dependencies in core
  • ✅ Seamless integration with Microsoft.Extensions.DependencyInjection

📦 Installation

Install from NuGet:

dotnet add package SierraStack.Mediator
dotnet add package SierraStack.Mediator.Behaviors
dotnet add package SierraStack.Mediator.Extensions.Microsoft

📌 See NuGet Gallery for all available packages.

🚀 Getting Started

1. Define a request

public class Ping : IRequest<string> 
{
    public string Message { get; set; } = "Ping!";
}

2. Define a handler

public class PingHandler : IRequestHandler<Ping, string>
{
    public Task<string> HandleAsync(Ping request, CancellationToken cancellationToken)
    {
        return Task.FromResult($"Pong: {request.Message}");
    }
}

3. Register services (using built-in DI)

services.AddSierraStackMediator(typeof(PingHandler).Assembly);
services.AddSierraStackBehaviors(); // optional

4. Use the mediator

var result = await mediator.SendAsync(new Ping());
// result => "Pong: Ping!"

🔌 Available Behaviors

Install SierraStack.Mediator.Behaviors and register built-in behaviors:

services.AddSierraStackBehaviors();

Or register them individually:

services
    .AddLoggingBehavior()
    .AddValidationBehavior(options =>
    {
        options.ThrowOnFailure = true;
        options.OnFailure = failures =>
        {
            foreach (var failure in failures)
                Console.WriteLine($"Validation failed: {failure.PropertyName} - {failure.ErrorMessage}");
        };
    });

Validation uses a SierraStack-specific abstraction and can integrate with FluentValidation or custom providers.

🧪 Testing

All core components and built-in behaviors are covered with unit tests using xUnit. To run:

dotnet test

📄 License

Licensed under the MIT License.

👋 Contributing

Contributions, suggestions, and ideas are welcome! Please open an issue or pull request to get started.

🔗 Repository

https://github.com/sierrastack/SierraStack

📍 See the full roadmap for upcoming features and plans.

SierraStack.Mediator Benchmarks

These benchmarks use BenchmarkDotNet to measure mediator performance across common scenarios.

Scenario Mean Allocated
Simple Request 633 ns 952 B
+ Logging Behavior TBD TBD
+ Logging + Retry TBD TBD

Run with:

dotnet run -c Release --project SierraStack.Mediator.Benchmarks

About

A modern alternative to MediatR—SierraStack starts with a lightweight mediator and grows into a full-stack .NET service framework.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors