Пример #1
0
        /// <summary>
        ///     Applies a use case to the <see cref="Actor"/> through a <see cref="IUseCaseRequest{TResponse}"/>.
        ///     If the <see cref="IUseCaseRequest{TResponse}"/> is not supported by the <see cref="IActor"/>
        ///     then the <see cref="Successor"/> will attempt to <see cref="IActor.Do{TResponse}(IUseCaseRequest{TResponse}, CancellationToken)"/>
        ///     the <see cref="IUseCaseRequest{TResponse}"/>.
        /// </summary>
        /// <typeparam name="TResponse">
        ///     The type for the response of the <see cref="IUseCaseRequest{TResponse}"/>.
        /// </typeparam>
        /// <param name="request">
        ///     The <see cref="IUseCaseRequest{TResponse}"/> to do by the <see cref="Actor"/> or its <see cref="Successor"/>.
        /// </param>
        /// <param name="cancellationToken">
        ///     Optional cancellation token for the <see cref="IUseCase{TRequest, TResponse}"/> operation.
        /// </param>
        /// <returns>
        ///     The value type wrapper around the <see cref="TResponse"/>.
        ///     The result type of which is <typeparamref name="TResponse"/>.
        /// </returns>
        /// <exception cref="InvalidOperationException">
        ///     Mediator has no receiver for the <see cref="IUseCaseRequest{TResponse}"/>.
        /// </exception>
        public async ValueTask <TResponse> Do <TResponse>(IUseCaseRequest <TResponse> request, CancellationToken cancellationToken = default)
            where TResponse
        : class
        {
            if (SupportsUseCaseWithResponse <TResponse>())
            {
                return((TResponse)await Mediator.Send(request, cancellationToken));
            }
            else if (Successor != null)
            {
                /// Since the <see cref="IUseCase{IUseCaseRequest{TResponse}, TResponse}"/> was not supported the <see cref="Successor"/>
                return(await Successor.Do(request, cancellationToken));
            }

            throw new InvalidOperationException($"{GetType().Name} does not support request {request.GetType().Name}");
        }
Пример #2
0
        public bool Equals(IUseCaseRequest <TResponse> x, IUseCaseRequest <TResponse> y)
        {
            if (x is null)
            {
                return(false);
            }

            if (y is null)
            {
                return(false);
            }

            if (!ReferenceEquals(x, y))
            {
                return(false);
            }

            if (x.GetHashCode() != y.GetHashCode())
            {
                return(false);
            }

            return(true);
        }
Пример #3
0
 public int GetHashCode(IUseCaseRequest <TResponse> obj)
 => obj is null ? 0 : RuntimeHelpers.GetHashCode(obj);
Пример #4
0
 public bool Equals(IUseCaseRequest <TResponse> other)
 => new UseCaseRequestEqualityComparer <TResponse>().Equals(this, other);