### Install MediatR with NuGet Package Manager Source: https://github.com/luckypennysoftware/mediatr/blob/main/README.md Use this command in the Package Manager Console to install the MediatR NuGet package. ```csharp Install-Package MediatR ``` -------------------------------- ### Install MediatR with .NET Core CLI Source: https://github.com/luckypennysoftware/mediatr/blob/main/README.md Use this command with the .NET Core CLI to add the MediatR package to your project. ```bash dotnet add package MediatR ``` -------------------------------- ### Implement a Logging Pipeline Behavior in C# Source: https://github.com/luckypennysoftware/mediatr/wiki/Behaviors This example demonstrates a basic logging behavior that logs when a request is handled and when a response is returned. It requires an `ILogger` instance for logging. The `next` delegate must be awaited to continue the pipeline. ```csharp public class LoggingBehavior : IPipelineBehavior where TRequest : IRequest { private readonly ILogger> _logger; public LoggingBehavior(ILogger> logger) { _logger = logger; } public async Task Handle(TRequest request, RequestHandlerDelegate next, CancellationToken cancellationToken) { _logger.LogInformation($ ``` -------------------------------- ### Usage Example for Generic Request Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Send a generic request through the mediator and process the response. Remember to include assemblies containing primitives if used as generic types. ```csharp var pong = await _mediator.Send(new GenericPing{ Pong = new() { Message = "Ping Pong" } }); Console.WriteLine(pong.Message); //would output "Ping Pong" ``` -------------------------------- ### Define a Request/Response Message Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Create a message class that implements IRequest for request/response scenarios. This example defines a 'Ping' message that expects a string response. ```csharp public class Ping : IRequest { } ``` -------------------------------- ### Implement Async Request Handler Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Example of an asynchronous request handler that uses await for background operations. Ensure handlers are registered with your IoC container. ```csharp public class PingHandler : IRequestHandler { public async Task Handle(Ping request, CancellationToken cancellationToken) { await DoPong(); // Whatever DoPong does } } ``` -------------------------------- ### Send a Request Message Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Send a request message through the mediator to its handler. This example sends a 'Ping' message and expects a string response. ```csharp var response = await mediator.Send(new Ping()); Debug.WriteLine(response); // "Pong" ``` -------------------------------- ### Registering Pipeline Behaviors in MediatR Source: https://github.com/luckypennysoftware/mediatr/wiki/Behaviors Demonstrates how to register closed generic and open generic pipeline behaviors using `AddMediatR`. Behaviors are executed in the order they are registered. For void handlers, `TResponse` is `Unit`. ```csharp services.AddMediatR(cfg => { cfg.AddBehavior, PingPongBehavior>(); cfg.AddOpenBehavior(typeof(OuterBehavior<,>)); cfg.AddOpenBehavior(typeof(InnerBehavior<,>)); cfg.AddOpenBehavior(typeof(ConstrainedBehavior<,>)); }); ``` -------------------------------- ### Configure MediatR License with Dependency Injection Source: https://github.com/luckypennysoftware/mediatr/wiki/License-Key-Configuration Use this method to set the commercial license key when integrating MediatR with Microsoft.Extensions.DependencyInjection. ```csharp services.AddMediatR(cfg => { cfg.LicenseKey = "License key here"; // Other configuration }); ``` -------------------------------- ### Configure MediatR License with Static Property Source: https://github.com/luckypennysoftware/mediatr/wiki/License-Key-Configuration For non-MS.Ext.DI scenarios, set the license key using a static property on the Mediator class. ```csharp Mediator.LicenseKey = "License key here"; ``` -------------------------------- ### Register MediatR Services from Assembly Containing Startup Source: https://github.com/luckypennysoftware/mediatr/blob/main/README.md Registers MediatR services and handlers by scanning the assembly containing the Startup class. This is a common way to set up MediatR in ASP.NET Core applications. ```csharp services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblyContaining()); ``` -------------------------------- ### Enable and Configure Generic Handler Registration Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Enable the registration of generic handlers and specify the assembly containing them. Ensure all relevant assemblies are included. ```csharp //you can also configure other values shown above here as well builder.Services.AddMediatR(cfg => { cfg.RegisterGenericHandlers = true; cfg.RegisterServicesFromAssembly(typeof(GenericPing<>).Assembly); }); ``` -------------------------------- ### Implement a Request Handler Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Implement the IRequestHandler interface to handle a specific request. This 'PingHandler' handles the 'Ping' request and returns 'Pong'. ```csharp public class PingHandler : IRequestHandler { public Task Handle(Ping request, CancellationToken cancellationToken) { return Task.FromResult("Pong"); } } ``` -------------------------------- ### Configure Generic Handler Registration Settings Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Set configuration options to control the behavior and constraints of MediatR's generic request handler registration. ```csharp /// /// Configure the maximum number of type parameters that a generic request handler can have. To Disable this constraint, set the value to 0. /// public int MaxGenericTypeParameters { get; set; } = 10; /// /// Configure the maximum number of types that can close a generic request type parameter constraint. To Disable this constraint, set the value to 0. /// public int MaxTypesClosing { get; set; } = 100; /// /// Configure the Maximum Amount of Generic RequestHandler Types MediatR will try to register. To Disable this constraint, set the value to 0. /// public int MaxGenericTypeRegistrations { get; set; } = 125000; /// /// Configure the Timeout in Milliseconds that the GenericHandler Registration Process will exit with error. To Disable this constraint, set the value to 0. /// public int RegistrationTimeout { get; set; } = 15000; /// /// Flag that controlls whether MediatR will attempt to register handlers that containg generic type parameters. /// public bool RegisterGenericHandlers { get; set; } = false; ``` -------------------------------- ### Create and Consume a Stream Request Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Create a stream request using the mediator and consume the streamed items using 'await foreach'. The CancellationTokenSource is used to cancel the stream after a certain condition. ```csharp CancellationTokenSource cts = new(); int count = 10; await foreach (var item in mediator.CreateStream(new CounterStreamRequest(), cts.Token)) { count--; if (count == 0) { cts.Cancel(); } Debug.WriteLine(item); } ``` -------------------------------- ### Register MediatR Services from a Specific Assembly Source: https://github.com/luckypennysoftware/mediatr/blob/main/README.md Registers MediatR services and handlers by explicitly specifying the assembly to scan. Useful when the Startup class is not in the same assembly as your handlers. ```csharp services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(Startup).Assembly)); ``` -------------------------------- ### Configure MediatR Services Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Configure MediatR services using IServiceCollection. Specify a license key and register services from a specific assembly. This registers core MediatR types like IMediator, ISender, and IPublisher. ```csharp services.AddMediatR(cfg => { cfg.LicenseKey = ""; cfg.RegisterServicesFromAssembly(typeof(Program).Assembly); }); ``` -------------------------------- ### Create Notification Handlers Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Implement the INotificationHandler interface for each notification type to define how notifications are processed. Multiple handlers can exist for a single notification. ```csharp public class Pong1 : INotificationHandler { public Task Handle(Ping notification, CancellationToken cancellationToken) { Debug.WriteLine("Pong 1"); return Task.CompletedTask; } } ``` ```csharp public class Pong2 : INotificationHandler { public Task Handle(Ping notification, CancellationToken cancellationToken) { Debug.WriteLine("Pong 2"); return Task.CompletedTask; } } ``` -------------------------------- ### Define Custom Notification Publisher Interface Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Implement this interface to create custom notification publishing strategies. This allows for advanced control over how notifications are delivered to handlers. ```csharp public interface INotificationPublisher { Task Publish(IEnumerable handlerExecutors, INotification notification, CancellationToken cancellationToken); } ``` -------------------------------- ### Migrate void Handle to protected override void HandleCore Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide---3.x-to-4.0 Use this regex to transform `public void Handle(TRequest request)` to `protected override void HandleCore(TRequest request)` for Mediator 4.0. ```regex `public void Handle\(([a-zA-Z0-9_<>]*) ([a-zA-Z0-9_<>]*)\)` ``` ```regex `protected override void HandleCore($1 $2)` ``` -------------------------------- ### Implement a Stream Request Handler Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Implement IStreamRequestHandler to handle stream requests. This handler generates integers asynchronously with a delay. ```csharp public sealed class CounterStreamHandler : IStreamRequestHandler { public async IAsyncEnumerable Handle(CounterStreamRequest request, [EnumeratorCancellation] CancellationToken cancellationToken) { int count = 0; while (!cancellationToken.IsCancellationRequested) { await Task.Delay(500, cancellationToken); yield return count; count++; } } } ``` -------------------------------- ### Migrate async Task Handle to protected override async Task HandleCore Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide---3.x-to-4.0 Use this regex to transform `public async Task Handle(TRequest request)` to `protected override async Task HandleCore(TRequest request)` for Mediator 4.0. ```regex `public async Task<([a-zA-Z0-9_<>]*)> Handle\(([a-zA-Z0-9_<>]*) ([a-zA-Z0-9_<>]*)\)` ``` ```regex `protected override async Task<$1> HandleCore($2 $3)` ``` -------------------------------- ### Migrate async Task Handle to protected override async Task HandleCore Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide---3.x-to-4.0 Use this regex to transform `public async Task Handle(TRequest request)` to `protected override async Task HandleCore(TRequest request)` for Mediator 4.0. ```regex `public async Task Handle\(([a-zA-Z0-9_<>]*) ([a-zA-Z0-9_<>]*)\)` ``` ```regex `protected override async Task HandleCore($1 $2)` ``` -------------------------------- ### Find and Replace for Handler Migration Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide-4.x-to-5.0 These regular expressions can be used with Find and Replace to migrate handler implementations. They cover changes from AsyncRequestHandler and HandleCore to IRequestHandler and Handle. ```regex : AsyncRequestHandler<(.*), (.*)>` | `: IRequestHandler<$1, $2>` ``` ```regex protected override async Task<(.*)> HandleCore\((.*)\)` | `public async Task<$1> Handle($2, CancellationToken cancellationToken)` ``` ```regex protected override Task<(.*)> HandleCore\((.*)\)` | `public Task<$1> Handle($2, CancellationToken cancellationToken)` ``` ```regex protected override async Task HandleCore\((.*)\)` | `protected override async Task Handle($1, CancellationToken cancellationToken)` ``` ```regex protected override (.*) HandleCore\((.*)\)` | `protected override $1 Handle($2)` ``` ```regex : AsyncNotificationHandler<(.*)>` | `: INotificationHandler<$1>` ``` -------------------------------- ### Migrating Void-Based Handlers to Unit Return Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide-4.x-to-5.0 When implementing IRequestHandler, return Task for void-based requests. Use Unit.Value for async/await or Unit.Task for pure Task-based methods. ```csharp public class Ping : IRequest { } public class PingHandler : IRequestHandler { public Task Handle(Ping request, CancellationToken cancellationToken) { // Work return Unit.Value; // for async/await return Unit.Task; // for pure Task-based methods } } ``` -------------------------------- ### Migrate Task Handle to protected override Task HandleCore Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide---3.x-to-4.0 Use this regex to transform `public Task Handle(TRequest request)` to `protected override Task HandleCore(TRequest request)` for Mediator 4.0. ```regex `public Task<([a-zA-Z0-9_<>]*)> Handle\(([a-zA-Z0-9_<>]*) ([a-zA-Z0-9_<>]*)\)` ``` ```regex `protected override Task<$1> HandleCore($2 $3)` ``` -------------------------------- ### Add MediatR Registration Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide-11.x-to-12.0 The AddMediatR extension method is now directly available from the MediatR package, consolidating functionality previously in MediatR.Extensions.Microsoft.DependencyInjection. ```csharp services.AddMediatR(/* registration */); ``` -------------------------------- ### Configure Custom Notification Publisher Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Register your custom notification publisher with the MediatR service configuration. You can specify either an instance or the type of your custom publisher. ```charp services.AddMediatR(cfg => { cfg.RegisterServicesFromAssemblyContaining(); cfg.NotificationPublisher = new MyCustomPublisher(); // this will be singleton cfg.NotificationPublisherType = typeof(MyCustomPublisher); // this will be the ServiceLifetime }); ``` -------------------------------- ### Add Generic Constraint to Pipeline Behavior Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide-9.x-to-10.0 When implementing open generic pipeline behaviors, add the `where TRequest : IRequest` constraint to comply with MediatR API changes. ```csharp public class GenericPipelineBehavior : IPipelineBehavior where TRequest : IRequest ``` -------------------------------- ### Register MediatR with Behaviors and Processors Source: https://github.com/luckypennysoftware/mediatr/blob/main/README.md Configures MediatR to include various pipeline behaviors, stream behaviors, and pre/post processors. This allows for cross-cutting concerns like logging or validation. ```csharp services.AddMediatR(cfg => { cfg.RegisterServicesFromAssembly(typeof(Startup).Assembly); cfg.AddBehavior(); cfg.AddStreamBehavior(); cfg.AddRequestPreProcessor(); cfg.AddRequestPostProcessor(); cfg.AddOpenBehavior(typeof(GenericBehavior<,>)); }); ``` -------------------------------- ### Define Generic Request and Handler Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Implement generic requests and handlers to write reusable logic for different type arguments. Ensure type constraints are met. ```csharp public interface IPong { string? Message { get; } } public class Pong : IPong { public string? Message { get; set; } } //generic request definition public class GenericPing : IRequest where T : class, IPong { public T? Pong { get; set; } } //generic request handler public class GenericPingHandler : IRequestHandler, T> where T : class, IPong { public Task Handle(GenericPing request, CancellationToken cancellationToken) => Task.FromResult(request.Pong!); } ``` -------------------------------- ### Define a Notification Message Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Create a class that implements the INotification interface to define a notification message. ```csharp public class Ping : INotification { } ``` -------------------------------- ### Consolidate MediatR Service Registration Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide-11.x-to-12.0 Replaces overloads for registering MediatR services with `IServiceCollection` by consolidating them into the `MediatrServiceConfiguration` object. Use `RegisterServicesFromAssembly` on the configuration object instead of the older `AddMediatR` overloads that accepted assemblies. ```diff -services.AddMediatR(typeof(Ping)); +services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(Ping).Assembly)); ``` -------------------------------- ### Set MediatR License Key Directly Source: https://github.com/luckypennysoftware/mediatr/blob/main/README.md Sets the MediatR license key directly on the `Mediator` class. Use this when not using `Microsoft.Extensions.DependencyInjection`. ```csharp Mediator.LicenseKey = ""; ``` -------------------------------- ### Migrate IAsyncRequestHandler to AsyncRequestHandler Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide---3.x-to-4.0 Use this find/replace to update `IAsyncRequestHandler` to `AsyncRequestHandler` for Mediator 4.0 migration. ```regex `IAsyncRequestHandler` ``` ```regex `AsyncRequestHandler` ``` -------------------------------- ### Implement a One-Way Request Handler Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Implement the IRequestHandler interface for requests that do not return a value. This handler performs work but returns Task.CompletedTask. ```csharp public class OneWayHandler : IRequestHandler { public Task Handle(OneWay request, CancellationToken cancellationToken) { // do work return Task.CompletedTask; } } ``` -------------------------------- ### Migrate ICancellableAsyncRequestHandler to IRequestHandler Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide---3.x-to-4.0 Use this find/replace to update `ICancellableAsyncRequestHandler` to `IRequestHandler` for Mediator 4.0 migration. ```regex `ICancellableAsyncRequestHandler` ``` ```regex `IRequestHandler` ``` -------------------------------- ### Publish a Notification Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Use the mediator instance to publish a notification, which will trigger all registered handlers for that notification type. ```csharp await mediator.Publish(new Ping()); ``` -------------------------------- ### Mute MediatR License Messages in Client Apps Source: https://github.com/luckypennysoftware/mediatr/wiki/License-Key-Configuration In client redistribution scenarios (Blazor WASM, WPF, MAUI, etc.), omit license key configuration and mute the license message category name to prevent secrets from being transmitted to the client. ```csharp builder.Logging.AddFilter("LuckyPennySoftware.MediatR.License", LogLevel.None); ``` -------------------------------- ### Define Request Handler Interface Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Defines the contravariant interface for handling requests, specifying the request and response types. ```csharp public interface IRequestHandler where TRequest : IRequest { Task Handle(TRequest message, CancellationToken cancellationToken); } ``` ```csharp public interface INotificationHandler { Task Handle(TNotification notification, CancellationToken cancellationToken); } ``` -------------------------------- ### Migrate IAsyncNotificationHandler to AsyncNotificationHandler Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide---3.x-to-4.0 Use this find/replace to update `IAsyncNotificationHandler` to `AsyncNotificationHandler` for Mediator 4.0 migration. ```regex `IAsyncNotificationHandler` ``` ```regex `AsyncNotificationHandler` ``` -------------------------------- ### Update Mediator Constructor for IServiceProvider Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide-11.x-to-12.0 The Mediator constructor now directly accepts IServiceProvider. If you were using a custom delegate, update to use IServiceProvider. The previous constructor signature is preserved with a default publisher. ```csharp public Mediator(IServiceProvider serviceProvider) : this(serviceProvider, new ForeachAwaitPublisher()) { } public Mediator(IServiceProvider serviceProvider, INotificationPublisher publisher) { _serviceProvider = serviceProvider; _publisher = publisher; } ``` -------------------------------- ### Update Void Request Handler Signature Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide-11.x-to-12.0 Void request handlers should now return Task instead of Task. Remove the Unit from the return type and use Task.CompletedTask or a simple return for async methods. ```csharp public interface IRequestHandler where TRequest : IRequest { Task Handle(TRequest request, CancellationToken cancellationToken); } ``` ```csharp public class VoidRequestHandler : IRequestHandler { public Task Handle(VoidRequest request, CancellationToken cancellationToken) { return Task.CompletedTask; } } ``` ```csharp public class VoidRequestHandler : IRequestHandler { public async Task Handle(VoidRequest request, CancellationToken cancellationToken) { await SomeThing(); return; } } ``` -------------------------------- ### Set MediatR License Key during Registration Source: https://github.com/luckypennysoftware/mediatr/blob/main/README.md Sets the MediatR license key when registering services with `IServiceCollection`. This is the recommended approach for ASP.NET Core applications. ```csharp services.AddMediatR(cfg => { cfg.LicenseKey = ""; }) ``` -------------------------------- ### Migrate IRequestHandler to RequestHandler Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide---3.x-to-4.0 Use this find/replace to update `IRequestHandler` to `RequestHandler` for Mediator 4.0 migration. ```regex `IRequestHandler` ``` ```regex `RequestHandler` ``` -------------------------------- ### Add Send Method for IRequest Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide-11.x-to-12.0 A new Send method overload has been added to the IMediator interface to specifically handle IRequest types without a generic return value. ```csharp public interface IMediator { Task Send(TRequest request, CancellationToken cancellationToken = default) where TRequest : IRequest; } ``` -------------------------------- ### Migrate generic Handle to generic HandleCore Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide---3.x-to-4.0 Use this regex to transform generic `public TResult Handle(TRequest request)` to `protected override TResult HandleCore(TRequest request)` for Mediator 4.0. ```regex `public ([a-zA-Z0-9_<>]*) Handle\(([a-zA-Z0-9_<>]*) ([a-zA-Z0-9_<>]*)\)` ``` ```regex `protected override $1 HandleCore($2 $3)` ``` -------------------------------- ### Migrate INotificationHandler to NotificationHandler Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide---3.x-to-4.0 Use this find/replace to update `INotificationHandler` to `NotificationHandler` for Mediator 4.0 migration. ```regex `INotificationHandler` ``` ```regex `NotificationHandler` ``` -------------------------------- ### Define a Stream Request Message Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Define a message for streaming responses by implementing IStreamRequest. This 'CounterStreamRequest' will stream integers. ```csharp public sealed class CounterStreamRequest : IStreamRequest { } ``` -------------------------------- ### Migrate Task Handle to protected override Task HandleCore Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide---3.x-to-4.0 Use this regex to transform `public Task Handle(TRequest request)` to `protected override Task HandleCore(TRequest request)` for Mediator 4.0. ```regex `public Task Handle\(([a-zA-Z0-9_<>]*) ([a-zA-Z0-9_<>]*)\)` ``` ```regex `protected override Task HandleCore($1 $2)` ``` -------------------------------- ### Request Exception Processor Behavior Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Defines a pipeline behavior for executing IRequestExceptionHandler instances after an exception occurs. This behavior is registered only if AddMediatR finds request exception behaviors. ```csharp namespace MediatR.Pipeline; /// /// Behavior for executing all instances /// after an exception is thrown by the following pipeline steps /// /// Request type /// Response type public class RequestExceptionProcessorBehavior : IRequestExceptionHandler where TRequest : notnull { ``` -------------------------------- ### Request Exception Action Processor Behavior Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Defines a pipeline behavior for executing IRequestExceptionAction instances after an exception occurs. If placed before RequestExceptionProcessorBehavior, actions are only called for unhandled exceptions. ```csharp namespace MediatR.Pipeline; /// /// Behavior for executing all instances /// after an exception is thrown by the following pipeline steps /// /// Request type /// Response type public class RequestExceptionActionProcessorBehavior : IRequestExceptionAction where TRequest : notnull { ``` -------------------------------- ### Modify Generic Constraint on IPipelineBehavior Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide-11.x-to-12.0 Rolls back generic constraints on IPipelineBehavior from `where TRequest : IRequest` to `where TRequest notnull` for greater flexibility. ```diff public class GenericPipelineBehavior : IPipelineBehavior - where TRequest : IRequest + where TRequest : notnull { ``` -------------------------------- ### Migrate ICancellableNotificationRequestHandler to INotificationHandler Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide---3.x-to-4.0 Use this find/replace to update `ICancellableNotificationRequestHandler` to `INotificationHandler` for Mediator 4.0 migration. ```regex `ICancellableNotificationRequestHandler` ``` ```regex `INotificationHandler` ``` -------------------------------- ### Update IRequest Interface Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide-11.x-to-12.0 The IRequest interface no longer inherits from IRequest. It now inherits from IBaseRequest to better support void handlers. ```csharp public interface IRequest : IBaseRequest { } ``` -------------------------------- ### Remove ServiceFactory Delegate Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide-11.x-to-12.0 The ServiceFactory delegate has been removed in favor of direct IServiceProvider injection. ```csharp public delegate object ServiceFactory(Type serviceType); ``` -------------------------------- ### Define a One-Way Request Source: https://github.com/luckypennysoftware/mediatr/wiki/Home Define a one-way message that does not require a response by implementing the non-generic IRequest interface. ```csharp public class OneWay : IRequest { } ``` -------------------------------- ### Inheriting AsyncRequestHandler for Unit Hiding Source: https://github.com/luckypennysoftware/mediatr/wiki/Migration-Guide-4.x-to-5.0 To use Unit.Value hiding, inherit from AsyncRequestHandler and change the interface handler method to 'protected override Task Handle(...)'. ```csharp protected override Task Handle(...) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.