Created
September 7, 2018 03:54
-
-
Save thangchung/4512fc438e98d930b41bc66057e57a16 to your computer and use it in GitHub Desktop.
Clean Domain-driven Design article - Add Product to a Cart
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 : TxRequestHandlerBase<InsertItemToNewCartRequest, InsertItemToNewCartResponse> | |
| { | |
| private readonly ICatalogGateway _catalogGateway; | |
| private readonly IShippingGateway _shippingGateway; | |
| private readonly IPromoGateway _promoGateway; | |
| public RequestHandler( | |
| IUnitOfWorkAsync uow, IQueryRepositoryFactory qrf, | |
| ICatalogGateway catalogGateway, IShippingGateway shippingGateway, | |
| IPromoGateway promoGateway) : base(uow, qrf) | |
| { | |
| _catalogGateway = catalogGateway; | |
| _shippingGateway = shippingGateway; | |
| _promoGateway = promoGateway; | |
| } | |
| public override async Task<InsertItemToNewCartResponse> Handle(InsertItemToNewCartRequest request, CancellationToken cancellationToken) | |
| { | |
| var cartCommander = UnitOfWork.Repository<Domain.Cart>(); | |
| var cart = await Domain.Cart.Load() | |
| .InsertItemToCart(request.ProductId, request.Quantity) | |
| .CalculateCartAsync(TaxType.NoTax, _catalogGateway, _promoGateway, _shippingGateway); | |
| await cartCommander.AddAsync(cart); | |
| await UnitOfWork.SaveChangesAsync(cancellationToken); | |
| return new InsertItemToNewCartResponse { Result = cart.ToDto() }; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment