Nuuvify.CommonPack.Mediator
3.0.0-test.25052502
dotnet add package Nuuvify.CommonPack.Mediator --version 3.0.0-test.25052502
NuGet\Install-Package Nuuvify.CommonPack.Mediator -Version 3.0.0-test.25052502
<PackageReference Include="Nuuvify.CommonPack.Mediator" Version="3.0.0-test.25052502" />
<PackageVersion Include="Nuuvify.CommonPack.Mediator" Version="3.0.0-test.25052502" />
<PackageReference Include="Nuuvify.CommonPack.Mediator" />
paket add Nuuvify.CommonPack.Mediator --version 3.0.0-test.25052502
#r "nuget: Nuuvify.CommonPack.Mediator, 3.0.0-test.25052502"
#addin nuget:?package=Nuuvify.CommonPack.Mediator&version=3.0.0-test.25052502&prerelease
#tool nuget:?package=Nuuvify.CommonPack.Mediator&version=3.0.0-test.25052502&prerelease
<img src="https://github.com/nuuvify/Nuuvify.CommonPack/blob/ed5c88dd485e97115f73dcb636a616af8416e2a8/Images/logonuuvify.jpg" alt="Nuuvify" width="300px" />
Mediator
Implementation of Mediator pattern for .net
Package | Version | Popularity |
---|---|---|
Nuuvify.CommonPack.Mediator |
Give a Star! ⭐
If this project is useful to you in any way, give me a star to help me maintain the project.
Samples
You can find complete example projects demonstrating how to use the Mediator in the /samples
folder.
These include:
- ✅ Basic usage with
Send
andPublish
- ✅ Modular application structure
- ✅ Manual and automatic registration of handlers
Feel free to explore and run them to see how the mediator works in different scenarios.
Getting Started
Installation
You can install the Mediator package via NuGet Package Manager or the .NET CLI:
dotnet add package Nuuvify.CommonPack.Mediator
1. Define the Request and Notification
public class CreateCustomerCommand : IRequest<string>
{
public string Name { get; set; }
}
public class CustomerCreatedEvent : INotification
{
public Guid CustomerId { get; }
public CustomerCreatedEvent(Guid customerId)
{
CustomerId = customerId;
}
}
2. Implement the Handlers
public class CreateCustomerHandler : IRequestHandler<CreateCustomerCommand, string>
{
private readonly IMediator _mediator;
public CreateCustomerHandler(IMediator mediator)
{
_mediator = mediator;
}
public async Task<string> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
{
var id = Guid.NewGuid();
await _mediator.Publish(new CustomerCreatedEvent(id), cancellationToken);
return $"Customer '{request.Name}' created with ID {id}";
}
}
public class SendWelcomeEmailHandler : INotificationHandler<CustomerCreatedEvent>
{
public Task Handle(CustomerCreatedEvent notification, CancellationToken cancellationToken)
{
Console.WriteLine($"Sending welcome email to customer {notification.CustomerId}");
return Task.CompletedTask;
}
}
3. Register the Handlers (Dependency Injection)
You can register everything manually if you want full control:
services.AddMediatoR();
4. Execute the Flow
public class CustomerAppService
{
private readonly IMediatoR _mediator;
public CustomerAppService(IMediatoR mediator)
{
_mediator = mediator;
}
public async Task<string> CreateCustomer(string name)
{
return await _mediator.Send(new CreateCustomerCommand { Name = name });
}
}
When the CreateCustomer
method is called:
CreateCustomerHandler
handles the request- It creates and persists the customer (simulated)
- It publishes a
CustomerCreatedEvent
SendWelcomeEmailHandler
handles the event
This structure cleanly separates commands (which change state and return a result) from notifications (which communicate to the rest of the system that something happened).
About
Nuuvify.CommonPack.Mediator was developed by Lincoln Zocateli under the MIT license.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.Extensions.DependencyInjection (>= 8.0.1)
- Nuuvify.CommonPack.Extensions (>= 3.0.0-test.25052502)
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
3.0.0-test.25052502 | 0 | 5/25/2025 |
3.0.0-test.25050204 | 0 | 5/2/2025 |
CHANGELOG.md