public async Task <Receipt> CalculateReceipt(string membershipId) { // Fan out Task <double> rebate = _rebateApi.GetRebate(membershipId); Task <double> subsidy = _subsidyApi.GetSubsidy(membershipId); Task <double> discount = _discountApi.GetDiscount(membershipId); // Fan in double[] results = await Task.WhenAll(rebate, subsidy, discount); return(new Receipt() { RebateAmount = results[0], SubsidyAmount = results[1], DiscountPercentage = results[2], MembershipId = membershipId, ReceiptId = Guid.NewGuid().ToString("N"), FinalAmount = 123 }); }
public async Task <ReceiptModel> Handle(GetReceiptByMembershipId request, CancellationToken cancellationToken) { // Fan out Task <double> rebate = _rebateApi.GetRebate(request._membershipId); Task <double> subsidy = _subsidyApi.GetSubsidy(request._membershipId); Task <double> discount = _discountApi.GetDiscount(request._membershipId); // Fan in double[] results = await Task.WhenAll(rebate, subsidy, discount); // build new domain entity var r = new Receipt(results[0], results[1], results[2]); // project to query model // Use imapper instead return(new ReceiptModel() { DiscountPercentage = r.DiscountPercentage, MembershipId = r.MembershipId, ReceiptId = r.ReceiptId, FinalAmount = r.Calculate() }); }