Processing
Overview
Support for CQS pattern on domain implementation.
Install
- ASOL.Core.Processing - contains CQS processing providers like CommandProcessor, QueryProcessor. Use this package when implementing processing.
- ASOL.Core.Processing.Abstractions - contains processing interfaces like ICommandProcessor, IQueryProcessor, ICommandHandler, IQueryHandler. Use this package when using processing.
- ASOL.Core.Processing.Primitives - contains processing primitives like ICommand, IQuery. Use this package when defining processing contracts.
Changelog
- 0.0.1.45802-dev
- Support for Application Insights has been removed; OpenTelemetry is now used instead. For proper functioning, the minimum required version of
ASOL.Core.Telemetry.Clientis0.0.1.45792-dev.
- Support for Application Insights has been removed; OpenTelemetry is now used instead. For proper functioning, the minimum required version of
Dependency injection
Mandatory dependency injection for CQS pattern.
/// <summary>
/// Add CQS infrastructure and all commands, queries and their handlers.
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddProcessingQueryAndCommands(this IServiceCollection services)
{
// Register all command handlers and query handlers and connect with their commands and queries.
services.Scan(scan =>
{
scan.FromAssembliesOf(typeof(BookCreateCommand))
.AddClasses(classes => classes.AssignableTo(typeof(ICommandHandler<,>)))
.AsImplementedInterfaces()
.WithTransientLifetime();
scan.FromAssembliesOf(typeof(BookCreateCommand))
.AddClasses(classes => classes.AssignableTo(typeof(ICommandHandler<>)))
.AsImplementedInterfaces()
.WithTransientLifetime();
scan.FromAssembliesOf(typeof(GetAllBooksQuery))
.AddClasses(classes => classes.AssignableTo(typeof(IQueryHandler<,>)))
.AsImplementedInterfaces()
.WithTransientLifetime();
});
// Register mandantory implementation.
services.AddScoped<ICommandHandlerProvider, CommandHandlerProvider>();
services.AddScoped<ICommandProcessor, CommandProcessor>();
services.AddScoped<IQueryHandlerProvider, QueryHandlerProvider>();
services.AddScoped<IQueryProcessor, QueryProcessor>();
return services;
}
Metrics
Each processed command and query (successful and unsuccessful) is counted using System.Diagnostics.Metrics.Counter metric.
Name of the counters:
- asol.core.processing.command.success
- asol.core.processing.command.failed
- asol.core.processing.query.success
- asol.core.processing.query.failed
The source of metrics is stored in the library ASOL.Core.Telemetry.Client.