How ricardorueda/mediatr works
Project type and purpose
• MediatR is an open-source .NET library (in-process messaging framework) implementing the Mediator pattern. It provides a zero-dependency core engine plus a contracts-only package, DI integration, pipeline behaviors, and sample applications demonstrating usage with various DI containers.
File structure
• Top-level directories:
• src – two projects:
◦ MediatR.Contracts (defines IRequest, INotification, IStreamRequest, Unit)
◦ MediatR (core implementation)
• samples – sample console/ASP.NET Core apps showing integration with Autofac, DryIoc, Lamar, LightInject, SimpleInjector, Windsor, Microsoft.Extensions.DependencyInjection, and custom publish strategies
• test – unit tests (MediatR.Tests) and benchmarks (MediatR.Benchmarks)
• Key sub-folders under src/MediatR:
• Entities, Internal – core object graphs and ordering logic
• Pipeline – pre/post processors, exception handlers, open-generic behaviors
• NotificationPublishers – different strategies for Publish (Task.WhenAll, foreach-await)
• MicrosoftExtensionsDI – ServiceCollectionExtensions and ServiceRegistrar for wiring into the Microsoft DI container
• Registration – centralized registration logic
• Wrappers – adapter classes for handlers
• Build scripts (Build.ps1, Push.ps1), GitHub workflows, NuGet.Config, and solution file tie everything together.
README for additional insights
• Purpose: “Simple mediator implementation in .NET,” supports request/response, commands, queries, notifications, streaming, sync/async, generic variance.
• Highlights: contracts-only package, DI registration via IServiceCollection extensions, ability to add custom behaviors, pre/post processors, stream behaviors, exception handlers.