• Stars
    star
    10,980
  • Rank 3,075 (Top 0.07 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple, unambitious mediator implementation in .NET

MediatR

CI NuGet NuGet MyGet (dev)

Simple mediator implementation in .NET

In-process messaging with no dependencies.

Supports request/response, commands, queries, notifications and events, synchronous and async with intelligent dispatching via C# generic variance.

Examples in the wiki.

Installing MediatR

You should install MediatR with NuGet:

Install-Package MediatR

Or via the .NET Core command line interface:

dotnet add package MediatR

Either commands, from Package Manager Console or .NET Core CLI, will download and install MediatR and all required dependencies.

Using Contracts-Only Package

To reference only the contracts for MediatR, which includes:

  • IRequest (including generic variants)
  • INotification
  • IStreamRequest

Add a package reference to MediatR.Contracts

This package is useful in scenarios where your MediatR contracts are in a separate assembly/project from handlers. Example scenarios include:

  • API contracts
  • GRPC contracts
  • Blazor

Registering with IServiceCollection

MediatR supports Microsoft.Extensions.DependencyInjection.Abstractions directly. To register various MediatR services and handlers:

services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblyContaining<Startup>());

or with an assembly:

services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(Startup).Assembly));

This registers:

  • IMediator as transient
  • ISender as transient
  • IPublisher as transient
  • IRequestHandler<,> concrete implementations as transient
  • IRequestHandler<> concrete implementations as transient
  • INotificationHandler<> concrete implementations as transient
  • IStreamRequestHandler<> concrete implementations as transient
  • IRequestExceptionHandler<,,> concrete implementations as transient
  • IRequestExceptionAction<,>) concrete implementations as transient

This also registers open generic implementations for:

  • INotificationHandler<>
  • IRequestExceptionHandler<,,>
  • IRequestExceptionAction<,>

To register behaviors, stream behaviors, pre/post processors:

services.AddMediatR(cfg => {
    cfg.RegisterServicesFromAssembly(typeof(Startup).Assembly);
    cfg.AddBehavior<PingPongBehavior>();
    cfg.AddStreamBehavior<PingPongStreamBehavior>();
    cfg.AddRequestPreProcessor<PingPreProcessor>();
    cfg.AddRequestPostProcessor<PingPongPostProcessor>();
    cfg.AddOpenBehavior(typeof(GenericBehavior<,>));
    });

With additional methods for open generics and overloads for explicit service types.

More Repositories

1

Respawn

Intelligent database cleaner for integration tests
C#
2,624
star
2

ContosoUniversityDotNetCore-Pages

With Razor Pages
C#
1,291
star
3

ContosoUniversityCore

JavaScript
589
star
4

presentations

Presentations I give
HTML
431
star
5

ContosoUniversityDotNetCore

JavaScript
424
star
6

ContosoUniversity

Contoso University sample re-done the way I would build it
JavaScript
394
star
7

MediatR.Extensions.Microsoft.DependencyInjection

MediatR extensions for Microsoft.Extensions.DependencyInjection
C#
327
star
8

bulk-writer

Provides guidance for fast ETL jobs, an IDataReader implementation for SqlBulkCopy (or the MySql or Oracle equivalents) that wraps an IEnumerable, and libraries for mapping entites to table columns.
C#
240
star
9

EntityFramework.Filters

Filters implementation for Entity Framework
C#
192
star
10

AdventureWorksCosmos

C#
96
star
11

nsb-diagnostics-poc

C#
70
star
12

SharpSSH

Fork of SharpSSH - SharpSSH is a pure .NET implementation of the SSH2 client protocol suite. It provides an API for communication with SSH servers and can be integrated into any .NET application.
C#
64
star
13

AzureAdExample

C#
50
star
14

MongoDB.Driver.Core.Extensions.DiagnosticSources

C#
42
star
15

NServiceBus.MessageRouting

Implementations of EIP message routing patterns
C#
41
star
16

QuartzNServiceBusSample

C#
39
star
17

MongoDB.Driver.Core.Extensions.OpenTelemetry

PowerShell
34
star
18

NServiceBus.Extensions.IntegrationTesting

C#
29
star
19

MicroservicesMessagingDemo

JavaScript
26
star
20

ddd-theory-and-practice-workshop-exercises

20
star
21

NServiceBus.Extensions.Diagnostics

C#
16
star
22

NServiceBus.Extensions.Diagnostics.OpenTelemetry

PowerShell
14
star
23

contosouniversitydocker

JavaScript
13
star
24

aspnetwebstack

C#
6
star
25

NServiceBusClassExample

C#
6
star
26

AutoMapper.EFCore

Port of https://github.com/AutoMapper/AutoMapper.EF6 for EF core.
C#
6
star
27

ndcsydney2017-cicd

JavaScript
5
star
28

contosouniversitydocker-linux

JavaScript
5
star
29

AzureMessagingServices

C#
5
star
30

blogexamples

Example code from posts on http://jimmybogard.lostechies.com
JavaScript
5
star
31

DotNetMigration

JavaScript
5
star
32

Oredev2016Workshop

C#
4
star
33

contosouniversity-rest

JavaScript
3
star
34

ContinuousDeliveryExample

JavaScript
3
star
35

rtd-tutorial

Python
2
star
36

NSBPerf

C#
2
star
37

AutoMapperSample

Sample Application for showing issue with AutoMapper
C#
1
star
38

NServiceBusProfiling

C#
1
star
39

sinatra-toto

Ruby
1
star
40

GenericVarianceContainerTests

C#
1
star
41

NServiceBusClassExamples

C#
1
star
42

kcdc2017-cicd

JavaScript
1
star