Skip to content

murunu/MediatorSourceGenerator

Repository files navigation

Mediator

Simple Mediator pattern implementation in .NET Heavily inspired by MediatR.

NativeAOT compatible, as it uses source generators instead of reflection.

Supports request/response and publishing of messages.

Disclaimer

Be aware this package is not meant for production use, as it is just made as a side-project.
Any bugs can be reported as a bug report in the issues panel.

Installing

Install-Package Murunu.Mediator

Usage

Registering default Mediator implementation:

To register the default Mediator implementation implement the following in your Program.cs file.

builder.Services.AddMediator();

This will implement all default services needed for the Mediator. To Register a receiver, add a scoped service to the DI container like following.

builder.Services.AddScoped<I(Async)Receiver, {YourReceiverType}>();

Make sure your implementation implements either IReceiver or IAsyncReceiver. See Implementation for more information.

Implementation

There is multiple choices for implementing a receiver. Make sure you choose the right one for your use case.

The main choices are between Sync and Async receivers.

Source Generator

If using the source generator, you do not have to add the receivers to the DI container.
The only thing that needs to be added for the source generator receivers is the [RegisterMediator] attribute.

Make sure to add the following to Program.cs

builder.Services.AddMediator()
    .AddSourceGenerator();

This adds all needed services to make the Mediator work with the source generator.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages