We provide IdentifiedCommand pattern to deduplicate incoming events with built-in EF backend (SqlServer/PostgreSQL) or Redis backend. Please follow the link Implement idempotent Commands for more information.
await mediator.Send(new IdentifiedCommand<OriginCommand>(originCommand, originCommandId));
The request manager will verify originCommandId does not exist before sending originCommand to your OriginCommandHandler.
Please register request management services with your application schema before use.
...
using Juice.MediatR.RequestManager.EF.DependencyInjection;
...
services.AddRequestManager(configuration, options =>
{
options.DatabaseProvider = "SqlServer"; // PostgreSQL
options.Schema = your-app-schema;
options.ConnectionName = "SqlServerConnection";
});
// migrate DB if needed
var context = resolver.ServiceProvider.GetRequiredService<ClientRequestContext>();
var pendingMigrations = await context.Database.GetPendingMigrationsAsync();
if (pendingMigrations.Any())
{
Console.WriteLine($"[{schema}][ClientRequestContext] You have {pendingMigrations.Count()} pending migrations to apply.");
Console.WriteLine("[ClientRequestContext] Applying pending migrations now");
await context.Database.MigrateAsync();
}
The library can be accessed via Nuget:
If you already have Redis so you can use it as a backend.
...
using Juice.MediatR.Redis.DependencyInjection;
...
services.AddRedisRequestManager(options =>
{
options.ConnectionString = configuration.GetConnectionString("Redis");
});
The library can be accessed via Nuget: