Automated formatting: BOM removal, using sort order, final newlines, whitespace normalization across all projects. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
77 lines
2.4 KiB
C#
77 lines
2.4 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Svrnty.CQRS.Abstractions;
|
|
using Svrnty.CQRS.Discovery;
|
|
|
|
namespace Svrnty.CQRS.Configuration;
|
|
|
|
/// <summary>
|
|
/// Builder for configuring CQRS services
|
|
/// </summary>
|
|
public class CqrsBuilder
|
|
{
|
|
/// <summary>
|
|
/// Gets the service collection for manual service registration
|
|
/// </summary>
|
|
public IServiceCollection Services { get; }
|
|
|
|
/// <summary>
|
|
/// Gets the CQRS configuration object (used by extension packages)
|
|
/// </summary>
|
|
public CqrsConfiguration Configuration { get; }
|
|
|
|
internal CqrsBuilder(IServiceCollection services)
|
|
{
|
|
Services = services;
|
|
Configuration = new CqrsConfiguration();
|
|
|
|
// Add discovery services by default
|
|
services.AddDefaultCommandDiscovery();
|
|
services.AddDefaultQueryDiscovery();
|
|
|
|
// Register configuration as singleton so it can be accessed later
|
|
services.AddSingleton(Configuration);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Completes the builder configuration
|
|
/// </summary>
|
|
internal void Build()
|
|
{
|
|
// Configuration is now handled by extension methods in respective packages
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds a command handler to the CQRS pipeline
|
|
/// </summary>
|
|
public CqrsBuilder AddCommand<TCommand, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TCommandHandler>()
|
|
where TCommand : class
|
|
where TCommandHandler : class, ICommandHandler<TCommand>
|
|
{
|
|
Services.AddCommand<TCommand, TCommandHandler>();
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds a command handler with result to the CQRS pipeline
|
|
/// </summary>
|
|
public CqrsBuilder AddCommand<TCommand, TResult, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TCommandHandler>()
|
|
where TCommand : class
|
|
where TCommandHandler : class, ICommandHandler<TCommand, TResult>
|
|
{
|
|
Services.AddCommand<TCommand, TResult, TCommandHandler>();
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds a query handler to the CQRS pipeline
|
|
/// </summary>
|
|
public CqrsBuilder AddQuery<TQuery, TResult, TQueryHandler>()
|
|
where TQuery : class
|
|
where TQueryHandler : class, IQueryHandler<TQuery, TResult>
|
|
{
|
|
Services.AddQuery<TQuery, TResult, TQueryHandler>();
|
|
return this;
|
|
}
|
|
}
|