Newer
Older
Cohesion / GetProductBySku2.cs
@Derek Comartin Derek Comartin on 6 May 2021 702 bytes Tests with interface and delegates
using System.Threading;
using System.Threading.Tasks;
using MediatR;

namespace Cohesion
{
    public class GetProductBySkuHandlerDelegateExample : IRequestHandler<GetProductBySkuRequest, ProductViewModel>
    {
        private readonly ProductDelegates.GetProductForSaleBySku _getProduct;

        public GetProductBySkuHandlerDelegateExample(ProductDelegates.GetProductForSaleBySku getProduct)
        {
            _getProduct = getProduct;
        }

        public async Task<ProductViewModel> Handle(GetProductBySkuRequest request, CancellationToken cancellationToken)
        {
            var product = await _getProduct(request.Sku);
            return product.ToViewModel();
        }
    }
}