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