dotnet-cqrs/Svrnty.CQRS.Grpc/GrpcCqrsOptions.cs
2025-11-04 16:45:54 -05:00

67 lines
1.8 KiB
C#

namespace Svrnty.CQRS.Grpc;
/// <summary>
/// Configuration options for gRPC CQRS endpoints
/// </summary>
public class GrpcCqrsOptions
{
/// <summary>
/// Gets whether reflection should be enabled
/// </summary>
public bool ShouldEnableReflection { get; private set; }
private bool ShouldMapCommands { get; set; }
private bool ShouldMapQueries { get; set; }
private bool WasMappingMethodCalled { get; set; }
/// <summary>
/// Enables gRPC reflection for the service
/// </summary>
public GrpcCqrsOptions EnableReflection()
{
ShouldEnableReflection = true;
return this;
}
/// <summary>
/// Maps command endpoints
/// </summary>
public GrpcCqrsOptions MapCommands()
{
WasMappingMethodCalled = true;
ShouldMapCommands = true;
return this;
}
/// <summary>
/// Maps query endpoints (includes dynamic queries)
/// </summary>
public GrpcCqrsOptions MapQueries()
{
WasMappingMethodCalled = true;
ShouldMapQueries = true;
return this;
}
/// <summary>
/// Maps both command and query endpoints
/// </summary>
public GrpcCqrsOptions MapCommandsAndQueries()
{
WasMappingMethodCalled = true;
ShouldMapCommands = true;
ShouldMapQueries = true;
return this;
}
/// <summary>
/// Gets whether commands should be mapped (defaults to true if no mapping methods were called)
/// </summary>
public bool GetShouldMapCommands() => WasMappingMethodCalled ? ShouldMapCommands : true;
/// <summary>
/// Gets whether queries should be mapped (defaults to true if no mapping methods were called)
/// </summary>
public bool GetShouldMapQueries() => WasMappingMethodCalled ? ShouldMapQueries : true;
}