Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ivanpaulovich/fluentmediator

:twisted_rightwards_arrows: FluentMediator is an unobtrusive library that allows developers to build custom pipelines for Commands, Queries and Events.
https://github.com/ivanpaulovich/fluentmediator

chain-methods chain-of-responsibility craftmanship csharp ddd-cqrs dotnet-core event-driven event-handlers event-sourcing fluent-design fluent-interface mediator-pattern message-bus pipeline-framework pipelines tdd

Last synced: 3 months ago
JSON representation

:twisted_rightwards_arrows: FluentMediator is an unobtrusive library that allows developers to build custom pipelines for Commands, Queries and Events.

Awesome Lists containing this project

README

        

# FluentMediator
[![Build Status](https://ivanpaulovich.visualstudio.com/FluentMediator/_apis/build/status/ivanpaulovich.FluentMediator?branchName=master)](https://ivanpaulovich.visualstudio.com/FluentMediator/_build/latest?definitionId=24&branchName=master) [![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors) ![GitHub issues](https://img.shields.io/github/issues/ivanpaulovich/FluentMediator) ![GitHub pull requests](https://img.shields.io/github/issues-pr/ivanpaulovich/FluentMediator) ![NuGet](https://buildstats.info/nuget/FluentMediator)

:twisted_rightwards_arrows: 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:

```c#
services.AddFluentMediator(builder => {
builder.On().Pipeline()
.Call((handler, request) => handler.MyMethod(request))
.Call((handler, request) => handler.MyLongMethod(request))
.Return(
(handler, request) => handler.MyOtherMethod(request)
);
});
```

Then you are able to use the injected `IMediator` interface.

### Publishing Events

```c#
// Puts the message in the pipeline, calls three handlers.
mediator.Publish(ping);
```

### Sending Commands and Queries

```c#
// Calls the three handlers then get the response from `MyOtherMethod(PingRequest)`.
PingResponse response = mediator.Send(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](https://github.com/ivanpaulovich/FluentMediator/issues), [Wiki](https://github.com/ivanpaulovich/FluentMediator/wiki) and [Samples](https://github.com/ivanpaulovich/FluentMediator/tree/master/samples).