From 3955ee9f398bd305aa6bc2e6015e8afbfd1aad2c Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 8 Apr 2026 15:34:39 +0200 Subject: [PATCH] Refactor Mediator GetOr API for naming consistency Renamed MediatorExtensions to MediatorGetOrContext and GetOrContext to MediatorGetOrContext for consistent naming. Moved the GetOr extension method into the new static class. Updated XML docs and reorganized declarations; no functional changes. --- ...rExtensions.cs => MediatorGetOrContext.cs} | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) rename EnvelopeGenerator.Application/Common/Extensions/{MediatorExtensions.cs => MediatorGetOrContext.cs} (89%) diff --git a/EnvelopeGenerator.Application/Common/Extensions/MediatorExtensions.cs b/EnvelopeGenerator.Application/Common/Extensions/MediatorGetOrContext.cs similarity index 89% rename from EnvelopeGenerator.Application/Common/Extensions/MediatorExtensions.cs rename to EnvelopeGenerator.Application/Common/Extensions/MediatorGetOrContext.cs index 010c3154..f43cd0a3 100644 --- a/EnvelopeGenerator.Application/Common/Extensions/MediatorExtensions.cs +++ b/EnvelopeGenerator.Application/Common/Extensions/MediatorGetOrContext.cs @@ -4,35 +4,18 @@ using System.Collections; namespace EnvelopeGenerator.Application.Common.Extensions; -/// -/// Extension methods for that provide a fluent API for enforcing non-null responses. -/// -public static class MediatorExtensions -{ - /// - /// Begins a fluent chain that sends and lets you choose how to handle a null or empty response. - /// Usage: - /// - /// await sender.GetOr(query).ThrowNotFound(); - /// await sender.GetOr(query, cancel).Throw(() => new MyException()); - /// - /// - public static GetOrContext GetOr(this ISender sender, IRequest request, CancellationToken cancel = default) - => new(sender, request, cancel); -} - /// /// Holds a pending MediatR request and exposes Throw… methods that send the request /// and throw a chosen exception when the response is null or an empty collection. /// /// The expected response type. -public readonly struct GetOrContext +public readonly struct MediatorGetOrContext { private readonly ISender _sender; private readonly IRequest _request; private readonly CancellationToken _cancel; - internal GetOrContext(ISender sender, IRequest request, CancellationToken cancel) + internal MediatorGetOrContext(ISender sender, IRequest request, CancellationToken cancel) { _sender = sender; _request = request; @@ -74,4 +57,21 @@ public readonly struct GetOrContext /// public Task ThrowBadRequest(string? message = null) => Throw(() => new BadRequestException(message ?? $"The request for {typeof(TResponse).Name} is invalid.")); +} + +/// +/// Extension methods for that provide a fluent API for enforcing non-null responses. +/// +public static class MediatorGetOrContext +{ + /// + /// Begins a fluent chain that sends and lets you choose how to handle a null or empty response. + /// Usage: + /// + /// await sender.GetOr(query).ThrowNotFound(); + /// await sender.GetOr(query, cancel).Throw(() => new MyException()); + /// + /// + public static MediatorGetOrContext GetOr(this ISender sender, IRequest request, CancellationToken cancel = default) + => new(sender, request, cancel); } \ No newline at end of file