Awesome Open Source
Awesome Open Source

FluentMediator

Build Status All Contributors GitHub issues GitHub pull requests NuGet

🔀 We will not require you to add dependencies into your domain or to implement frameworks interfaces in your event handlers. Finally a really loosely coupled mediator library was born.

Install

Install-Package FluentMediator

For seameless .NET Core integration:

Install-Package FluentMediator.Microsoft.Extensions.DependencyInjection

How

Setup your events and pipelines using depedency injection. You can be very creative here! It supports async methods and cancellable tokens parameters, you could append multiple steps select one to return a message. An example:

services.AddFluentMediator(builder => {
    builder.On<PingRequest>().Pipeline()
        .Call<IPingHandler>((handler, request) => handler.MyMethod(request))
        .Call<IPingHandler>((handler, request) => handler.MyLongMethod(request))
        .Return<PingResponse, IPingHandler>(
            (handler, request) => handler.MyOtherMethod(request)
        );
});

Then you are able to use the injected IMediator interface.

Publishing Events

// Puts the message in the pipeline, calls three handlers.
mediator.Publish<PingRequest>(ping);

Sending Commands and Queries

// Calls the three handlers then get the response from `MyOtherMethod(PingRequest)`.
PingResponse response = mediator.Send<PingResponse>(new PingRequest("Ping"));
Console.WriteLine(response.Message); // Prints "Pong"

Why

When designing CQRS or Event-Driven applications we need to publish events from the infrastructure layer into the domain event handlers. We do not want framework dependencies leaking out to the Model then FluentMediator was born.

Contributors

Ivan Paulovich
Ivan Paulovich

💻 🎨 ⚠️
Joakim Carselind
Joakim Carselind

👀 🤔
Vaggelis Mparmpas
Vaggelis Mparmpas

⚠️

Please contribute with Issues, Wiki and Samples.


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
C Sharp (178,460
Pipeline (15,606
Test Driven Development (4,298
Arrow (3,957
Twisted (1,296
Event Sourcing (1,132
Event Driven (795
Event Handlers (548
Message Bus (397
Fluent Interface (353
Fluent Design (162
Pipeline Framework (85
Mediator Pattern (80
Chain Of Responsibility (38
Ddd Cqrs (33
Chain Methods (7
Craftmanship (7