Pulse.Mediator
1.0.7
dotnet add package Pulse.Mediator --version 1.0.7
NuGet\Install-Package Pulse.Mediator -Version 1.0.7
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pulse.Mediator" Version="1.0.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pulse.Mediator" Version="1.0.7" />
<PackageReference Include="Pulse.Mediator" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Pulse.Mediator --version 1.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Pulse.Mediator, 1.0.7"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Pulse.Mediator@1.0.7
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Pulse.Mediator&version=1.0.7
#tool nuget:?package=Pulse.Mediator&version=1.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Pulse.Mediator
Zero-dependency, in-house CQRS mediator for .NET — a drop-in replacement for MediatR.
Install
dotnet add package Pulse.Mediator
Core concepts
| Type | Purpose |
|---|---|
IRequest<TResponse> |
A request that returns TResponse |
IRequest |
A void command (returns Unit) |
IRequestHandler<TRequest, TResponse> |
Handles a typed request |
IRequestHandler<TRequest> |
Handles a void command |
INotification |
A domain event / notification |
INotificationHandler<TNotification> |
Handles a published notification |
IPipelineBehavior<TRequest, TResponse> |
Wraps a handler (logging, validation, etc.) |
IMediator |
Dispatches requests and publishes notifications |
Setup
// Program.cs
builder.Services
.AddPulseMediator(typeof(MyHandler).Assembly)
.AddPipelineBehavior(typeof(LoggingBehaviour<,>))
.AddPipelineBehavior(typeof(ValidationBehaviour<,>));
Commands
// Define
public record CreatePatientCommand(string Name, string NhisId) : IRequest<Guid>;
// Handle
public class CreatePatientCommandHandler(IPatientRepository repo)
: IRequestHandler<CreatePatientCommand, Guid>
{
public async Task<Guid> Handle(CreatePatientCommand request, CancellationToken ct)
{
var patient = Patient.Create(request.Name, request.NhisId);
await repo.AddAsync(patient, ct);
return patient.Id;
}
}
// Dispatch
var id = await mediator.Send(new CreatePatientCommand("Ama Owusu", "GHA-123456"));
Void commands
public record DeletePatientCommand(Guid Id) : IRequest;
public class DeletePatientCommandHandler(IPatientRepository repo)
: IRequestHandler<DeletePatientCommand>
{
public async Task Handle(DeletePatientCommand request, CancellationToken ct)
=> await repo.DeleteAsync(request.Id, ct);
}
await mediator.Send(new DeletePatientCommand(patientId));
Notifications (domain events)
public record PatientRegistered(Guid PatientId, string Name) : INotification;
public class SendWelcomeSmsHandler : INotificationHandler<PatientRegistered>
{
public Task Handle(PatientRegistered n, CancellationToken ct) => ...;
}
await mediator.Publish(new PatientRegistered(id, "Ama Owusu"));
Pipeline behaviors
public sealed class LoggingBehaviour<TRequest, TResponse>(ILogger<TRequest> logger)
: IPipelineBehavior<TRequest, TResponse>
where TRequest : notnull
{
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken ct)
{
logger.LogInformation("Handling {Request}", typeof(TRequest).Name);
var response = await next(ct);
logger.LogInformation("Handled {Request}", typeof(TRequest).Name);
return response;
}
}
License
MIT — Midas Path Software Solutions
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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 is compatible. 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 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
-
net8.0
-
net9.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.