Created
September 7, 2018 03:52
-
-
Save thangchung/11582bfffaaa7c4207547c40d871b847 to your computer and use it in GitHub Desktop.
Clean Domain-driven Design article - Get Cart with Products
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class RequestHandler : RequestHandlerBase<GetCartRequest, GetCartResponse> | |
| { | |
| private readonly ICatalogGateway _catalogGateway; | |
| private readonly IShippingGateway _shippingGateway; | |
| private readonly IPromoGateway _promoGateway; | |
| public RequestHandler(ICatalogGateway cgw, IQueryRepositoryFactory qrf, | |
| IShippingGateway shippingGateway, IPromoGateway promoGateway) | |
| : base(qrf) | |
| { | |
| _catalogGateway = cgw; | |
| _shippingGateway = shippingGateway; | |
| _promoGateway = promoGateway; | |
| } | |
| public override async Task<GetCartResponse> Handle(GetCartRequest request, CancellationToken cancellationToken) | |
| { | |
| var cartQuery = QueryFactory.QueryEfRepository<Domain.Cart>(); | |
| var cart = await cartQuery.GetFullCartAsync(request.CartId, false) | |
| .ToObservable() | |
| .SelectMany(async c => | |
| await c.CalculateCartAsync(TaxType.NoTax, _catalogGateway, _promoGateway, _shippingGateway)); | |
| return new GetCartResponse { Result = cart.ToDto() }; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment