Extensibility contracts and abstractions for the Pulse CQRS mediator library. This package defines the core interfaces and abstractions required to implement the mediator pattern with Command Query Responsibility Segregation (CQRS) principles. It provides strongly-typed contracts for commands (ICommand, ICommandHandler), queries (IQuery), events (IEvent, IEventHandler), and request/response patterns (IRequest, IRequestHandler). The extensibility model includes interceptor interfaces (ICommandInterceptor, IQueryInterceptor, IEventInterceptor, IRequestInterceptor) for implementing cross-cutting concerns such as validation, logging, caching, authentication, and transaction management. This package is designed to be framework-agnostic and serves as the foundation for building testable, maintainable, and decoupled application architectures. Perfect for domain-driven design (DDD), clean architecture, and hexagonal architecture patterns where business logic needs to be isolated from infrastructure concerns.
$ dotnet add package NetEvolve.Pulse.ExtensibilityNetEvolve.Pulse.Extensibility delivers the core contracts for building CQRS mediators: commands, queries, events, handlers, interceptors, and configurators that compose the Pulse pipeline.
IMediatorConfigurator and extension methodsVoid responses and TimeProvider awarenessInstall-Package NetEvolve.Pulse.Extensibility
dotnet add package NetEvolve.Pulse.Extensibility
<PackageReference Include="NetEvolve.Pulse.Extensibility" Version="x.x.x" />
using NetEvolve.Pulse.Extensibility;
public record CreateInvoiceCommand(string CustomerId, decimal Amount) : ICommand<InvoiceCreated>;
public record InvoiceCreated(Guid InvoiceId);
public sealed class CreateInvoiceHandler
: ICommandHandler<CreateInvoiceCommand, InvoiceCreated>
{
public Task<InvoiceCreated> HandleAsync(
CreateInvoiceCommand command,
CancellationToken cancellationToken) =>
Task.FromResult(new InvoiceCreated(Guid.NewGuid()));
}
public record GetInvoiceQuery(Guid Id) : IQuery<Invoice>;
public record Invoice(Guid Id, string CustomerId, decimal Amount);
public sealed class GetInvoiceHandler : IQueryHandler<GetInvoiceQuery, Invoice>
{
public Task<Invoice> HandleAsync(GetInvoiceQuery query, CancellationToken cancellationToken) =>
Task.FromResult(new Invoice(query.Id, "CUST-123", 125.00m));
}
Pair the contracts with the Pulse mediator for DI and dispatching:
using Microsoft.Extensions.DependencyInjection;
using NetEvolve.Pulse;
using NetEvolve.Pulse.Extensibility;
var services = new ServiceCollection();
services.AddPulse();
services.AddScoped<ICommandHandler<CreateInvoiceCommand, InvoiceCreated>, CreateInvoiceHandler>();
services.AddScoped<IQueryHandler<GetInvoiceQuery, Invoice>, GetInvoiceHandler>();
var provider = services.BuildServiceProvider();
var mediator = provider.GetRequiredService<IMediator>();
var created = await mediator.SendAsync<CreateInvoiceCommand, InvoiceCreated>(
new CreateInvoiceCommand("CUST-123", 125.00m));
var invoice = await mediator.QueryAsync<GetInvoiceQuery, Invoice>(
new GetInvoiceQuery(created.InvoiceId));
Extend the configurator with your own interceptors and plug them into Pulse:
using NetEvolve.Pulse.Extensibility;
public static class MediatorConfiguratorExtensions
{
public static IMediatorConfigurator AddCustomValidation(
this IMediatorConfigurator configurator)
{
// Register validation interceptors or pipelines here
return configurator;
}
}
// Register with Pulse
services.AddPulse(config =>
{
config.AddActivityAndMetrics()
.AddCustomValidation();
});
// Configure mediator features during startup
services.AddPulse(config =>
{
// Built-in observability interceptors
config.AddActivityAndMetrics();
// Custom extension methods for validation, caching, retries, etc.
// config.AddCustomValidation();
});
AddActivityAndMetrics() through PulseFor complete documentation, please visit the official documentation.
Contributions are welcome! Please read the Contributing Guidelines before submitting a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
[!NOTE] Made with ❤️ by the NetEvolve Team