OpenMediator 1.1.3
dotnet add package OpenMediator --version 1.1.3
NuGet\Install-Package OpenMediator -Version 1.1.3
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="OpenMediator" Version="1.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenMediator" Version="1.1.3" />
<PackageReference Include="OpenMediator" />
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 OpenMediator --version 1.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: OpenMediator, 1.1.3"
#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.
#addin nuget:?package=OpenMediator&version=1.1.3
#tool nuget:?package=OpenMediator&version=1.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
OpenMediator
Alternative for those who do not want to pay for a mediator implementation.
Configuration
In your Program.cs call AddOpenMediator
services.AddOpenMediator(config =>
{
config.RegisterCommandsFromAssemblies([Assembly.GetExecutingAssembly()]);
});
Usage
1 Create commands
public record CreateUserCommand(int Id, string Name) : ICommand;
2 Call MediatorBus
[ApiController]
[Route("api/user")]
public class UserController(IMediatorBus _mediator) : ControllerBase
{
[HttpPost()]
public async Task<IActionResult> CreateUser()
{
var command = new CreateUserCommand(1, "UserTest");
await _mediator.SendAsync(command);
return Ok();
}
}
3 Define your use case
public record CreateUserCommandHandler(ILogger<CreateUserCommandHandler> _logger) : ICommandHandler<CreateUserCommand>
{
public async Task HandleAsync(CreateUserCommand command)
{
// Simulate some work
await Task.Delay(1000);
}
}
Middleware Configuration
Also you can configure and execute custom middlewares before or after the command.
- Define your middleware by implementing the
IMediatorMiddleware
interface:
public class CustomMediatorMiddleware() : IMediatorMiddleware
{
public async Task ExecuteAsync<TCommand>(TCommand command, Func<Task> next)
where TCommand : ICommand
{
// Do something before the command
await Task.Delay(500);
await next();
// Do something after the command
await Task.Delay(500);
}
public async Task<TResponse> ExecuteAsync<TCommand, TResponse>(TCommand command, Func<Task<TResponse>> next)
where TCommand : ICommand<TResponse>
{
// Do something before the command
await Task.Delay(500);
var result = await next();
// Do something after the command
await Task.Delay(500);
return result;
}
}
- Register your middlewares in the
AddOpenMediator
method:
services.AddOpenMediator(config =>
{
config.RegisterCommandsFromAssemblies([Assembly.GetExecutingAssembly()]);
config.RegisterMiddleware<CustomMediatorMiddleware>();
});
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 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
-
net9.0
NuGet packages (2)
Showing the top 2 NuGet packages that depend on OpenMediator:
Package | Downloads |
---|---|
OpenMediator.Shared.Integration.Test
Package Description |
|
OpenMediator.Shared.Test
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.