From 098000573ab6e9baf31164d1e30c77956aacda12 Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Tue, 16 May 2017 15:07:08 +0200 Subject: [PATCH 01/11] Change property name --- .../Events/OrderStockNotConfirmedIntegrationEvent.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs b/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs index 8186f8a13..be57329c7 100644 --- a/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs +++ b/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs @@ -7,13 +7,13 @@ { public int OrderId { get; } - public IEnumerable OrderStockItem { get; } + public List OrderStockItems { get; } - public OrderStockNotConfirmedIntegrationEvent(int orderId, - IEnumerable orderStockItem) + public OrderStockNotConfirmedIntegrationEvent(int orderId, + List orderStockItems) { OrderId = orderId; - OrderStockItem = orderStockItem; + OrderStockItems = orderStockItems; } } From a757bb58f0165da5dc6733b769bb578615705c71 Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Tue, 16 May 2017 15:07:30 +0200 Subject: [PATCH 02/11] Add stockunit to products in CatalogContextSeed --- .../Infrastructure/CatalogContextSeed.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs b/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs index 5f2370fb6..9752b46db 100644 --- a/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs +++ b/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs @@ -70,18 +70,18 @@ { return new List() { - new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Bot Black Hoodie", Name = ".NET Bot Black Hoodie", Price = 19.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/1" }, - new CatalogItem() { CatalogTypeId=1,CatalogBrandId=2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/2" }, - new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/3" }, - new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation T-shirt", Name = ".NET Foundation T-shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/4" }, - new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/5" }, - new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Hoodie", Name = ".NET Blue Hoodie", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/6" }, - new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/7" }, - new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Hoodie", Name = "Kudu Purple Hoodie", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/8" }, - new CatalogItem() { CatalogTypeId=1,CatalogBrandId=5, Description = "Cup White Mug", Name = "Cup White Mug", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/9" }, - new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/10" }, - new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup Sheet", Name = "Cup Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/11" }, - new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/12" } + new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Bot Black Hoodie", Name = ".NET Bot Black Hoodie", Price = 19.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/1", AvailableStock = 1}, + new CatalogItem() { CatalogTypeId=1,CatalogBrandId=2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/2", AvailableStock = 1 }, + new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/3", AvailableStock = 1 }, + new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation T-shirt", Name = ".NET Foundation T-shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/4", AvailableStock = 1 }, + new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/5", AvailableStock = 1 }, + new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Hoodie", Name = ".NET Blue Hoodie", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/6", AvailableStock = 1 }, + new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/7", AvailableStock = 1 }, + new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Hoodie", Name = "Kudu Purple Hoodie", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/8", AvailableStock = 1 }, + new CatalogItem() { CatalogTypeId=1,CatalogBrandId=5, Description = "Cup White Mug", Name = "Cup White Mug", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/9", AvailableStock = 1 }, + new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/10", AvailableStock = 1 }, + new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup Sheet", Name = "Cup Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/11", AvailableStock = 1 }, + new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/12", AvailableStock = 1 } }; } } From 4cd594bebca0772cd9d0e90b52154753ea726552 Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Tue, 16 May 2017 15:08:02 +0200 Subject: [PATCH 03/11] Declare PayOrderCommandMsg class DI --- src/Services/Payment/Payment.API/Startup.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Services/Payment/Payment.API/Startup.cs b/src/Services/Payment/Payment.API/Startup.cs index 7899d9aa6..38968eef3 100644 --- a/src/Services/Payment/Payment.API/Startup.cs +++ b/src/Services/Payment/Payment.API/Startup.cs @@ -48,6 +48,7 @@ namespace Payment.API services.AddSingleton(); services.AddSingleton(); + services.AddTransient>(); services.AddSwaggerGen(); services.ConfigureSwaggerGen(options => From a5b0fd31cb6752fd8c6e5446a52833a2c50ad369 Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Tue, 16 May 2017 15:10:23 +0200 Subject: [PATCH 04/11] Get ChildItems --- .../Ordering.API/Application/Sagas/OrderSaga.cs | 11 ++++------- .../Repositories/OrderRepository.cs | 5 ++++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Services/Ordering/Ordering.API/Application/Sagas/OrderSaga.cs b/src/Services/Ordering/Ordering.API/Application/Sagas/OrderSaga.cs index dd8e46ac7..babc66188 100644 --- a/src/Services/Ordering/Ordering.API/Application/Sagas/OrderSaga.cs +++ b/src/Services/Ordering/Ordering.API/Application/Sagas/OrderSaga.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate; @@ -20,10 +18,9 @@ namespace Ordering.API.Application.Sagas public override Order FindSagaById(int id) { var order = _orderingContext.Orders - .Single(c => c.Id == id); - - _orderingContext.Entry(order) - .Member("OrderStatus"); + .Include(c => c.OrderStatus) + .Include(c => c.OrderItems) + .Single(c => c.Id == id); return order; } diff --git a/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs b/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs index 84ef46dfb..1dbc00690 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs @@ -33,7 +33,10 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor public async Task GetAsync(int orderId) { - return await _context.Orders.FindAsync(orderId); + return await _context.Orders + .Include(c => c.OrderStatus) + .Include(c => c.OrderItems) + .SingleAsync(c => c.Id == orderId); } public void Update(Order order) From d59ee8e817d167b8bb0beec1830c1fc009f98350 Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Tue, 16 May 2017 15:11:03 +0200 Subject: [PATCH 05/11] SaveChangesAsync() from Integration events --- ...derPaymentFailedIntegrationEventHandler.cs | 2 ++ ...rPaymentSuccededIntegrationEventHandler.cs | 2 ++ ...erStockConfirmedIntegrationEventHandler.cs | 2 ++ ...tockNotConfirmedIntegrationEventHandler.cs | 2 ++ .../Application/Sagas/OrderProcessSaga.cs | 5 ++--- .../AggregatesModel/OrderAggregate/Order.cs | 19 ++++++++----------- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs index 1e4e79978..259b7ec34 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs @@ -20,6 +20,8 @@ var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId); orderToUpdate.SetCancelledStatus(); + + await _orderRepository.UnitOfWork.SaveEntitiesAsync(); } } } diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs index f3075eeec..0e8598dcc 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs @@ -20,6 +20,8 @@ var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId); orderToUpdate.SetPaidStatus(); + + await _orderRepository.UnitOfWork.SaveEntitiesAsync(); } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs index 60c8bb65d..fa7463041 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs @@ -20,6 +20,8 @@ var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId); orderToUpdate.SetStockConfirmedStatus(); + + await _orderRepository.UnitOfWork.SaveEntitiesAsync(); } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs index 68a89885c..b38b56b21 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs @@ -26,6 +26,8 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling .Select(c => c.ProductId); orderToUpdate.SetStockConfirmedStatus(orderStockNotConfirmedItems); + + await _orderRepository.UnitOfWork.SaveChangesAsync(); } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs b/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs index 12e6a3fa2..f230ba6fb 100644 --- a/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs +++ b/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs @@ -43,15 +43,14 @@ namespace Ordering.API.Application.Sagas /// period has completed. /// /// - public async Task Handle(ConfirmGracePeriodCommandMsg @event) + public async Task Handle(ConfirmGracePeriodCommandMsg command) { - var orderSaga = FindSagaById(@event.OrderId); + var orderSaga = FindSagaById(command.OrderId); CheckValidSagaId(orderSaga); if (orderSaga.OrderStatus != OrderStatus.Cancelled) { orderSaga.SetAwaitingValidationStatus(); - await SaveChangesAsync(); } } diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs index 64bb2d21d..518f22d9c 100644 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs +++ b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs @@ -30,7 +30,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O // but only through the method OrderAggrergateRoot.AddOrderItem() which includes behaviour. private readonly List _orderItems; - public IEnumerable OrderItems => _orderItems.AsReadOnly(); + public IReadOnlyList OrderItems => _orderItems; // Using List<>.AsReadOnly() // This will create a read only wrapper around the private list so is protected against "external updates". // It's much cheaper than .ToList() because it will not have to copy all items in a new collection. (Just one heap alloc for the wrapper instance) @@ -107,9 +107,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O StatusChangeException(); } - _orderStatusId = OrderStatus.AwaitingValidation.Id; + AddDomainEvent(new OrderStatusChangedToAwaitingValidationDomainEvent(Id, _orderItems)); - AddDomainEvent(new OrderStatusChangedToAwaitingValidationDomainEvent(Id, OrderItems)); + _orderStatusId = OrderStatus.AwaitingValidation.Id; } public void SetStockConfirmedStatus(IEnumerable orderStockNotConfirmedItems = null) @@ -121,15 +121,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O if (orderStockNotConfirmedItems is null) { - OrderStatus = OrderStatus.StockConfirmed; + AddDomainEvent(new OrderStatusChangedToStockConfirmedDomainEvent(Id)); + _orderStatusId = OrderStatus.StockConfirmed.Id; _description = "All the items were confirmed with available stock."; - - AddDomainEvent(new OrderStatusChangedToStockConfirmedDomainEvent(Id)); } else { - OrderStatus = OrderStatus.Cancelled; + _orderStatusId = OrderStatus.Cancelled.Id; var itemsStockNotConfirmedProductNames = OrderItems .Where(c => orderStockNotConfirmedItems.Contains(c.ProductId)) @@ -147,10 +146,10 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O StatusChangeException(); } + AddDomainEvent(new OrderStatusChangedToPaidDomainEvent(Id, OrderItems)); + _orderStatusId = OrderStatus.Paid.Id; _description = "The payment was performed at a simulated \"American Bank checking bank account endinf on XX35071\""; - - AddDomainEvent(new OrderStatusChangedToPaidDomainEvent(Id, OrderItems)); } public void SetShippedStatus() @@ -162,8 +161,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O _orderStatusId = OrderStatus.Shipped.Id; _description = ""; - - //Call Domain Event } public void SetCancelledStatus() From 12dd8acef9feb83dd1193761f06720798498f8fa Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Tue, 16 May 2017 15:44:21 +0200 Subject: [PATCH 06/11] add rabbitmq dependency in Payment.api container and IPaymentIntegrationEventService DI --- docker-compose.yml | 2 ++ src/Services/Payment/Payment.API/Startup.cs | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 75177c5db..55d84e39e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -90,3 +90,5 @@ services: build: context: ./src/Services/Payment/Payment.API dockerfile: Dockerfile + depends_on: + - rabbitmq diff --git a/src/Services/Payment/Payment.API/Startup.cs b/src/Services/Payment/Payment.API/Startup.cs index 38968eef3..b8b3b9b66 100644 --- a/src/Services/Payment/Payment.API/Startup.cs +++ b/src/Services/Payment/Payment.API/Startup.cs @@ -11,6 +11,7 @@ using Payment.API.IntegrationCommands.Commands; using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ; using RabbitMQ.Client; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; +using Payment.API.IntegrationEvents; namespace Payment.API { @@ -34,6 +35,7 @@ namespace Payment.API // Add framework services. services.AddMvc(); + services.AddTransient(); services.AddSingleton(sp => { var logger = sp.GetRequiredService>(); @@ -45,10 +47,10 @@ namespace Payment.API return new DefaultRabbitMQPersistentConnection(factory, logger); }); - services.AddSingleton(); services.AddSingleton(); services.AddTransient>(); + services.AddSwaggerGen(); services.ConfigureSwaggerGen(options => From aaa821bb49e97d4abb2c2250fcb53bfc7f2f4bc6 Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Tue, 16 May 2017 18:39:54 +0200 Subject: [PATCH 07/11] Modify payment DI --- .../CommandHandlers/PayOrderCommandMsgHandler.cs | 5 ++++- src/Services/Payment/Payment.API/Payment.API.csproj | 3 +++ src/Services/Payment/Payment.API/Startup.cs | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Services/Payment/Payment.API/IntegrationCommands/CommandHandlers/PayOrderCommandMsgHandler.cs b/src/Services/Payment/Payment.API/IntegrationCommands/CommandHandlers/PayOrderCommandMsgHandler.cs index c0023909c..178b36474 100644 --- a/src/Services/Payment/Payment.API/IntegrationCommands/CommandHandlers/PayOrderCommandMsgHandler.cs +++ b/src/Services/Payment/Payment.API/IntegrationCommands/CommandHandlers/PayOrderCommandMsgHandler.cs @@ -12,7 +12,10 @@ private readonly IPaymentIntegrationEventService _paymentIntegrationEventService; public PayOrderCommandMsgHandler(IPaymentIntegrationEventService paymentIntegrationEventService) - => _paymentIntegrationEventService = paymentIntegrationEventService; + { + _paymentIntegrationEventService = paymentIntegrationEventService; + } + public async Task Handle(PayOrderCommandMsg @event) { diff --git a/src/Services/Payment/Payment.API/Payment.API.csproj b/src/Services/Payment/Payment.API/Payment.API.csproj index 7f741fa53..de3636585 100644 --- a/src/Services/Payment/Payment.API/Payment.API.csproj +++ b/src/Services/Payment/Payment.API/Payment.API.csproj @@ -29,6 +29,9 @@ + + + diff --git a/src/Services/Payment/Payment.API/Startup.cs b/src/Services/Payment/Payment.API/Startup.cs index b8b3b9b66..eaef3f704 100644 --- a/src/Services/Payment/Payment.API/Startup.cs +++ b/src/Services/Payment/Payment.API/Startup.cs @@ -12,6 +12,7 @@ using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ; using RabbitMQ.Client; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; using Payment.API.IntegrationEvents; +using Payment.API.IntegrationCommands.CommandHandlers; namespace Payment.API { @@ -49,7 +50,7 @@ namespace Payment.API }); services.AddSingleton(); services.AddSingleton(); - services.AddTransient>(); + services.AddTransient, PayOrderCommandMsgHandler>(); services.AddSwaggerGen(); From 3556a5d126d2c58efd2c0fd24bcfd2754ae92261 Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Tue, 16 May 2017 18:40:34 +0200 Subject: [PATCH 08/11] Change SaveEntitiesAsync to SaveChangesAsync --- ...OrderStatusChangedToPaidDomainEventHandler.cs | 5 ----- .../OrderPaymentFailedIntegrationEventHandler.cs | 4 ++-- ...rderPaymentSuccededIntegrationEventHandler.cs | 4 ++-- ...OrderStockConfirmedIntegrationEventHandler.cs | 4 ++-- ...erStockNotConfirmedIntegrationEventHandler.cs | 2 +- src/Services/Ordering/Ordering.API/Startup.cs | 16 +++++++++++----- .../OrderAggregate/IOrderRepository.cs | 2 ++ .../AggregatesModel/OrderAggregate/Order.cs | 2 +- .../Repositories/OrderRepository.cs | 5 +++++ 9 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs index 1eb4a8953..3aff01578 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs @@ -41,11 +41,6 @@ orderStockList); await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(decrementOrderStockCommandMsg); await _orderingIntegrationEventService.PublishThroughEventBusAsync(decrementOrderStockCommandMsg); - - //is it necessary get a DecrementOrderStockSuccessIntegrationEvent/DecrementOrderStockFailedIntegrationEvent before to call ShipOrderCommandMsg??? - var shipOrderCommandMsg = new ShipOrderCommandMsg(orderStatusChangedToPaidDomainEvent.OrderId); - await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(shipOrderCommandMsg); - await _orderingIntegrationEventService.PublishThroughEventBusAsync(shipOrderCommandMsg); } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs index 259b7ec34..49b252e4a 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs @@ -17,11 +17,11 @@ public async Task Handle(OrderPaymentFailedIntegrationEvent @event) { - var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId); + var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId); orderToUpdate.SetCancelledStatus(); - await _orderRepository.UnitOfWork.SaveEntitiesAsync(); + await _orderRepository.UnitOfWork.SaveChangesAsync(); } } } diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs index 0e8598dcc..fc813ff2d 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs @@ -17,11 +17,11 @@ public async Task Handle(OrderPaymentSuccededIntegrationEvent @event) { - var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId); + var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId); orderToUpdate.SetPaidStatus(); - await _orderRepository.UnitOfWork.SaveEntitiesAsync(); + await _orderRepository.UnitOfWork.SaveChangesAsync(); } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs index fa7463041..172444932 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs @@ -17,11 +17,11 @@ public async Task Handle(OrderStockConfirmedIntegrationEvent @event) { - var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId); + var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId); orderToUpdate.SetStockConfirmedStatus(); - await _orderRepository.UnitOfWork.SaveEntitiesAsync(); + await _orderRepository.UnitOfWork.SaveChangesAsync(); } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs index b38b56b21..918e4f094 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs @@ -19,7 +19,7 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling public async Task Handle(OrderStockNotConfirmedIntegrationEvent @event) { - var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId); + var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId); var orderStockNotConfirmedItems = @event.OrderStockItems .FindAll(c => !c.Confirmed) diff --git a/src/Services/Ordering/Ordering.API/Startup.cs b/src/Services/Ordering/Ordering.API/Startup.cs index 95014dd5b..e2b0734f7 100644 --- a/src/Services/Ordering/Ordering.API/Startup.cs +++ b/src/Services/Ordering/Ordering.API/Startup.cs @@ -32,6 +32,7 @@ using System; using System.Data.Common; using System.Reflection; + using global::Ordering.API.Application.IntegrationEvents.EventHandling; public class Startup { @@ -129,8 +130,14 @@ services.AddSingleton(); services.AddTransient>(); services.AddTransient, OrderProcessSaga>(); - services.AddTransient>(); - services.AddTransient>(); + services.AddTransient, + OrderStockConfirmedIntegrationEventHandler>(); + services.AddTransient, + OrderStockNotConfirmedIntegrationEventHandler>(); + services.AddTransient, + OrderPaymentFailedIntegrationEventHandler>(); + services.AddTransient, + OrderPaymentSuccededIntegrationEventHandler>(); services.AddOptions(); //configure autofac @@ -176,12 +183,11 @@ var eventBus = app.ApplicationServices.GetRequiredService(); eventBus.Subscribe>(); - eventBus.Subscribe>(); - eventBus.Subscribe>(); - eventBus.Subscribe>(); + eventBus.Subscribe>(); + eventBus.Subscribe>(); } protected virtual void ConfigureAuth(IApplicationBuilder app) diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs index d7346ee4f..368410d62 100644 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs +++ b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs @@ -13,5 +13,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O void Update(Order order); Task GetAsync(int orderId); + + Task GetWithDependenciesAsync(int orderId); } } diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs index 518f22d9c..51c201e6b 100644 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs +++ b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs @@ -30,7 +30,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O // but only through the method OrderAggrergateRoot.AddOrderItem() which includes behaviour. private readonly List _orderItems; - public IReadOnlyList OrderItems => _orderItems; + public IReadOnlyCollection OrderItems => _orderItems; // Using List<>.AsReadOnly() // This will create a read only wrapper around the private list so is protected against "external updates". // It's much cheaper than .ToList() because it will not have to copy all items in a new collection. (Just one heap alloc for the wrapper instance) diff --git a/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs b/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs index 1dbc00690..df7b07aaa 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs @@ -32,6 +32,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor } public async Task GetAsync(int orderId) + { + return await _context.Orders.FindAsync(orderId); + } + + public async Task GetWithDependenciesAsync(int orderId) { return await _context.Orders .Include(c => c.OrderStatus) From 587de20d852436ae6e96b4f7652de3c258790d15 Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Tue, 16 May 2017 18:57:36 +0200 Subject: [PATCH 09/11] revert the last changes --- .../EventHandling/OrderPaymentFailedIntegrationEventHandler.cs | 2 +- .../OrderPaymentSuccededIntegrationEventHandler.cs | 2 +- .../EventHandling/OrderStockConfirmedIntegrationEventHandler.cs | 2 +- .../OrderStockNotConfirmedIntegrationEventHandler.cs | 2 +- src/Services/SagaManager/SagaManager/Program.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs index 49b252e4a..3f81f8f67 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs @@ -21,7 +21,7 @@ orderToUpdate.SetCancelledStatus(); - await _orderRepository.UnitOfWork.SaveChangesAsync(); + await _orderRepository.UnitOfWork.SaveEntitiesAsync(); } } } diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs index fc813ff2d..80144d0ed 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs @@ -21,7 +21,7 @@ orderToUpdate.SetPaidStatus(); - await _orderRepository.UnitOfWork.SaveChangesAsync(); + await _orderRepository.UnitOfWork.SaveEntitiesAsync(); } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs index 172444932..ac4bc5936 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs @@ -21,7 +21,7 @@ orderToUpdate.SetStockConfirmedStatus(); - await _orderRepository.UnitOfWork.SaveChangesAsync(); + await _orderRepository.UnitOfWork.SaveEntitiesAsync(); } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs index 918e4f094..f3003c0a4 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs @@ -27,7 +27,7 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling orderToUpdate.SetStockConfirmedStatus(orderStockNotConfirmedItems); - await _orderRepository.UnitOfWork.SaveChangesAsync(); + await _orderRepository.UnitOfWork.SaveEntitiesAsync(); } } } \ No newline at end of file diff --git a/src/Services/SagaManager/SagaManager/Program.cs b/src/Services/SagaManager/SagaManager/Program.cs index 95105b23b..c902492cd 100644 --- a/src/Services/SagaManager/SagaManager/Program.cs +++ b/src/Services/SagaManager/SagaManager/Program.cs @@ -45,7 +45,7 @@ namespace SagaManager while (true) { sagaManagerService.CheckFinishedGracePeriodOrders(); - await Task.Delay(30000); + await Task.Delay(90000); } } From 8b80eeae523718e68fe2d72e4ff0e86538cb0e00 Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Wed, 17 May 2017 00:40:40 +0200 Subject: [PATCH 10/11] minor changes --- src/Services/Basket/Basket.API/Startup.cs | 6 ---- .../DecrementOrderStockCommandMsgHandler.cs | 3 -- src/Services/Catalog/Catalog.API/Startup.cs | 17 +++++++--- .../Commands/CreateOrderCommandHandler.cs | 2 +- ...dToAwaitingValidationDomainEventHandler.cs | 2 -- ...erStatusChangedToPaidDomainEventHandler.cs | 2 -- ...angedToStockConfirmedDomainEventHandler.cs | 2 -- ...derPaymentFailedIntegrationEventHandler.cs | 2 +- ...rPaymentSuccededIntegrationEventHandler.cs | 2 +- ...erStockConfirmedIntegrationEventHandler.cs | 2 +- ...tockNotConfirmedIntegrationEventHandler.cs | 2 +- .../Application/Sagas/OrderProcessSaga.cs | 28 +++++----------- src/Services/Ordering/Ordering.API/Startup.cs | 32 +++++++++++-------- .../AggregatesModel/OrderAggregate/Order.cs | 14 ++------ .../Events/ConfirmGracePeriodCommandMsg.cs | 5 +-- .../SagaManagerIntegrationEventService.cs | 10 ++---- .../SagaManager/SagaManager/Program.cs | 31 +++++++----------- .../Services/SagaManagerService.cs | 19 +++-------- 18 files changed, 67 insertions(+), 114 deletions(-) diff --git a/src/Services/Basket/Basket.API/Startup.cs b/src/Services/Basket/Basket.API/Startup.cs index 2c1e70645..84f6c0570 100644 --- a/src/Services/Basket/Basket.API/Startup.cs +++ b/src/Services/Basket/Basket.API/Startup.cs @@ -165,12 +165,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API protected virtual void ConfigureEventBus(IApplicationBuilder app) { - var catalogPriceHandler = app.ApplicationServices - .GetService>(); - - var orderStartedHandler = app.ApplicationServices - .GetService>(); - var eventBus = app.ApplicationServices.GetRequiredService(); eventBus.Subscribe(); diff --git a/src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandMsgHandler.cs b/src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandMsgHandler.cs index 9268aa0ba..a6bc43228 100644 --- a/src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandMsgHandler.cs +++ b/src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandMsgHandler.cs @@ -3,9 +3,6 @@ using BuildingBlocks.EventBus.Abstractions; using System.Threading.Tasks; using Infrastructure; - using global::Catalog.API.Infrastructure.Exceptions; - using global::Catalog.API.IntegrationEvents; - using Model; using Commands; public class DecrementOrderStockCommandMsgHandler : IIntegrationEventHandler diff --git a/src/Services/Catalog/Catalog.API/Startup.cs b/src/Services/Catalog/Catalog.API/Startup.cs index 22dd201d0..1820e1f04 100644 --- a/src/Services/Catalog/Catalog.API/Startup.cs +++ b/src/Services/Catalog/Catalog.API/Startup.cs @@ -121,10 +121,7 @@ return new DefaultRabbitMQPersistentConnection(factory, logger); }); - services.AddSingleton(); - services.AddSingleton(); - services.AddTransient, ConfirmOrderStockCommandMsgHandler>(); - services.AddTransient, DecrementOrderStockCommandMsgHandler>(); + RegisterServiceBus(services); var container = new ContainerBuilder(); container.Populate(services); @@ -188,6 +185,18 @@ } } + private void RegisterServiceBus(IServiceCollection services) + { + services.AddSingleton(); + services.AddSingleton(); + + services.AddTransient, + ConfirmOrderStockCommandMsgHandler>(); + services.AddTransient, + DecrementOrderStockCommandMsgHandler>(); + + } + private void ConfigureEventBus(IApplicationBuilder app) { var eventBus = app.ApplicationServices.GetRequiredService(); diff --git a/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs b/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs index 3ef80a69a..938f80a9c 100644 --- a/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs @@ -43,7 +43,7 @@ // make sure that consistency is preserved across the whole aggregate var address = new Address(message.Street, message.City, message.State, message.Country, message.ZipCode); var order = new Order(message.UserId, address, message.CardTypeId, message.CardNumber, message.CardSecurityNumber, message.CardHolderName, message.CardExpiration); - order.SetSubmitedStatus(); + foreach (var item in message.OrderItems) { order.AddOrderItem(item.ProductId, item.ProductName, item.UnitPrice, item.Discount, item.PictureUrl, item.Units); diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs index d6906705f..06fd8bcfe 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs @@ -28,8 +28,6 @@ public async Task Handle(OrderStatusChangedToAwaitingValidationDomainEvent orderStatusChangedToAwaitingValidationDomainEvent) { - await _orderRepository.UnitOfWork.SaveEntitiesAsync(); - _logger.CreateLogger(nameof(OrderStatusChangedToAwaitingValidationDomainEvent)) .LogTrace($"Order with Id: {orderStatusChangedToAwaitingValidationDomainEvent.OrderId} has been successfully updated with " + $"a status order id: {OrderStatus.AwaitingValidation.Id}"); diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs index 3aff01578..ade15b149 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs @@ -28,8 +28,6 @@ public async Task Handle(OrderStatusChangedToPaidDomainEvent orderStatusChangedToPaidDomainEvent) { - await _orderRepository.UnitOfWork.SaveEntitiesAsync(); - _logger.CreateLogger(nameof(OrderStatusChangedToPaidDomainEventHandler)) .LogTrace($"Order with Id: {orderStatusChangedToPaidDomainEvent.OrderId} has been successfully updated with " + $"a status order id: {OrderStatus.Paid.Id}"); diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs index 2de4f5095..55b6d6c9a 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs @@ -27,8 +27,6 @@ public async Task Handle(OrderStatusChangedToStockConfirmedDomainEvent orderStatusChangedToStockConfirmedDomainEvent) { - await _orderRepository.UnitOfWork.SaveEntitiesAsync(); - _logger.CreateLogger(nameof(OrderStatusChangedToStockConfirmedDomainEventHandler)) .LogTrace($"Order with Id: {orderStatusChangedToStockConfirmedDomainEvent.OrderId} has been successfully updated with " + $"a status order id: {OrderStatus.StockConfirmed.Id}"); diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs index 49b252e4a..3f81f8f67 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs @@ -21,7 +21,7 @@ orderToUpdate.SetCancelledStatus(); - await _orderRepository.UnitOfWork.SaveChangesAsync(); + await _orderRepository.UnitOfWork.SaveEntitiesAsync(); } } } diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs index fc813ff2d..80144d0ed 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs @@ -21,7 +21,7 @@ orderToUpdate.SetPaidStatus(); - await _orderRepository.UnitOfWork.SaveChangesAsync(); + await _orderRepository.UnitOfWork.SaveEntitiesAsync(); } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs index 172444932..ac4bc5936 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs @@ -21,7 +21,7 @@ orderToUpdate.SetStockConfirmedStatus(); - await _orderRepository.UnitOfWork.SaveChangesAsync(); + await _orderRepository.UnitOfWork.SaveEntitiesAsync(); } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs index 918e4f094..f3003c0a4 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs @@ -27,7 +27,7 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling orderToUpdate.SetStockConfirmedStatus(orderStockNotConfirmedItems); - await _orderRepository.UnitOfWork.SaveChangesAsync(); + await _orderRepository.UnitOfWork.SaveEntitiesAsync(); } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs b/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs index f230ba6fb..08b699a1f 100644 --- a/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs +++ b/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs @@ -48,11 +48,8 @@ namespace Ordering.API.Application.Sagas var orderSaga = FindSagaById(command.OrderId); CheckValidSagaId(orderSaga); - if (orderSaga.OrderStatus != OrderStatus.Cancelled) - { - orderSaga.SetAwaitingValidationStatus(); - await SaveChangesAsync(); - } + orderSaga.SetAwaitingValidationStatus(); + await SaveChangesAsync(); } /// @@ -67,14 +64,9 @@ namespace Ordering.API.Application.Sagas var orderSaga = FindSagaById(command.OrderNumber); CheckValidSagaId(orderSaga); - // Not possible to cancel order when - // it has already been shipped - if (orderSaga.GetOrderStatusId() != OrderStatus.Cancelled.Id - || orderSaga.GetOrderStatusId() != OrderStatus.Shipped.Id) - { - orderSaga.SetCancelledStatus(); - result = await SaveChangesAsync(); - } + orderSaga.SetCancelledStatus(); + result = await SaveChangesAsync(); + return result; } @@ -90,13 +82,9 @@ namespace Ordering.API.Application.Sagas var orderSaga = FindSagaById(command.OrderNumber); CheckValidSagaId(orderSaga); - // Only ship order when - // its status is paid - if (orderSaga.GetOrderStatusId() == OrderStatus.Paid.Id) - { - orderSaga.SetShippedStatus(); - result = await SaveChangesAsync(); - } + orderSaga.SetShippedStatus(); + result = await SaveChangesAsync(); + return result; } diff --git a/src/Services/Ordering/Ordering.API/Startup.cs b/src/Services/Ordering/Ordering.API/Startup.cs index e2b0734f7..6f7828721 100644 --- a/src/Services/Ordering/Ordering.API/Startup.cs +++ b/src/Services/Ordering/Ordering.API/Startup.cs @@ -8,8 +8,6 @@ using global::Ordering.API.Application.IntegrationEvents.Events; using global::Ordering.API.Application.Sagas; using global::Ordering.API.Infrastructure.Middlewares; - using global::Ordering.API.Application.IntegrationCommands.Commands; - using global::Ordering.API.Application.Sagas; using Infrastructure; using Infrastructure.Auth; using Infrastructure.AutofacModules; @@ -126,18 +124,7 @@ return new DefaultRabbitMQPersistentConnection(factory, logger); }); - services.AddSingleton(); - services.AddSingleton(); - services.AddTransient>(); - services.AddTransient, OrderProcessSaga>(); - services.AddTransient, - OrderStockConfirmedIntegrationEventHandler>(); - services.AddTransient, - OrderStockNotConfirmedIntegrationEventHandler>(); - services.AddTransient, - OrderPaymentFailedIntegrationEventHandler>(); - services.AddTransient, - OrderPaymentSuccededIntegrationEventHandler>(); + RegisterServiceBus(services); services.AddOptions(); //configure autofac @@ -178,6 +165,23 @@ } + private void RegisterServiceBus(IServiceCollection services) + { + services.AddSingleton(); + services.AddSingleton(); + + services.AddTransient>(); + services.AddTransient, OrderProcessSaga>(); + services.AddTransient, + OrderStockConfirmedIntegrationEventHandler>(); + services.AddTransient, + OrderStockNotConfirmedIntegrationEventHandler>(); + services.AddTransient, + OrderPaymentFailedIntegrationEventHandler>(); + services.AddTransient, + OrderPaymentSuccededIntegrationEventHandler>(); + } + private void ConfigureEventBus(IApplicationBuilder app) { var eventBus = app.ApplicationServices.GetRequiredService(); diff --git a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs index 51c201e6b..eaecba5f9 100644 --- a/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs +++ b/src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs @@ -95,14 +95,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O } #region Status Changes - public void SetSubmitedStatus() - { - _orderStatusId = OrderStatus.Submited.Id; - } public void SetAwaitingValidationStatus() { - if (_orderStatusId != OrderStatus.Submited.Id) + if (_orderStatusId != OrderStatus.Submited.Id && + _orderStatusId != OrderStatus.Cancelled.Id) { StatusChangeException(); } @@ -167,7 +164,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O { if (_orderStatusId == OrderStatus.Submited.Id) { - _description = "The order was cancelled before the grace period was confirm."; + _description = "The order was cancelled before the grace period was confirmed."; } else if (_orderStatusId == OrderStatus.AwaitingValidation.Id) { @@ -191,11 +188,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O #endregion - public int GetOrderStatusId() - { - return _orderStatusId; - } - private void AddOrderStartedDomainEvent(string userId, int cardTypeId, string cardNumber, string cardSecurityNumber, string cardHolderName, DateTime cardExpiration) { diff --git a/src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommandMsg.cs b/src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommandMsg.cs index fc47f44e5..6521cd200 100644 --- a/src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommandMsg.cs +++ b/src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommandMsg.cs @@ -2,13 +2,10 @@ { using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; - // Integration Events notes: - // An Event is “something that has happened in the past”, therefore its name has to be - // An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems. public class ConfirmGracePeriodCommandMsg : IntegrationEvent { public int OrderId { get;} public ConfirmGracePeriodCommandMsg(int orderId) => OrderId = orderId; } -} +} \ No newline at end of file diff --git a/src/Services/SagaManager/SagaManager/IntegrationEvents/SagaManagerIntegrationEventService.cs b/src/Services/SagaManager/SagaManager/IntegrationEvents/SagaManagerIntegrationEventService.cs index 3643c0530..5107881ef 100644 --- a/src/Services/SagaManager/SagaManager/IntegrationEvents/SagaManagerIntegrationEventService.cs +++ b/src/Services/SagaManager/SagaManager/IntegrationEvents/SagaManagerIntegrationEventService.cs @@ -9,13 +9,9 @@ private readonly IEventBus _eventBus; public SagaManagerIntegrationEventService(IEventBus eventBus) - { - _eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus)); - } + => _eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus)); - public void PublishThroughEventBus(IntegrationEvent evt) - { - _eventBus.Publish(evt); - } + + public void PublishThroughEventBus(IntegrationEvent evt) => _eventBus.Publish(evt); } } \ No newline at end of file diff --git a/src/Services/SagaManager/SagaManager/Program.cs b/src/Services/SagaManager/SagaManager/Program.cs index 95105b23b..08eb95157 100644 --- a/src/Services/SagaManager/SagaManager/Program.cs +++ b/src/Services/SagaManager/SagaManager/Program.cs @@ -1,34 +1,27 @@ -using System.Reflection; -using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; -using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure; -using Microsoft.EntityFrameworkCore; -using SagaManager.IntegrationEvents; - -namespace SagaManager +namespace SagaManager { using System.IO; using System; + using System.Threading.Tasks; + using Autofac.Extensions.DependencyInjection; + using Autofac; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ; + using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using RabbitMQ.Client; using Services; - using Autofac.Extensions.DependencyInjection; - using Autofac; - using System.Threading.Tasks; + using IntegrationEvents; public class Program { public static IConfigurationRoot Configuration { get; set; } - public static void Main(string[] args) - { - MainAsync().Wait(); - } - + public static void Main(string[] args) => MainAsync().Wait(); + static async Task MainAsync() { StartUp(); @@ -45,7 +38,7 @@ namespace SagaManager while (true) { sagaManagerService.CheckFinishedGracePeriodOrders(); - await Task.Delay(30000); + await Task.Delay(300000); } } @@ -66,8 +59,7 @@ namespace SagaManager .Configure(Configuration) .AddSingleton() .AddSingleton() - .AddSingleton() - .AddSingleton() + .AddSingleton(sp => { var settings = sp.GetRequiredService>().Value; @@ -78,8 +70,7 @@ namespace SagaManager }; return new DefaultRabbitMQPersistentConnection(factory, logger); - }) - .AddSingleton(); + }); RegisterServiceBus(services); diff --git a/src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs b/src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs index b40c2fb08..7ef5ae25a 100644 --- a/src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs +++ b/src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs @@ -1,12 +1,9 @@ -using System; -using System.Threading.Tasks; -using Microsoft.Extensions.Logging; - -namespace SagaManager.Services +namespace SagaManager.Services { using System.Collections.Generic; using System.Data.SqlClient; using Microsoft.Extensions.Options; + using Microsoft.Extensions.Logging; using Dapper; using IntegrationEvents; using IntegrationEvents.Events; @@ -32,7 +29,9 @@ namespace SagaManager.Services foreach (var orderId in orderIds) { - Publish(orderId); + var confirmGracePeriodEvent = new ConfirmGracePeriodCommandMsg(orderId); + + _sagaManagerIntegrationEventService.PublishThroughEventBus(confirmGracePeriodEvent); } } @@ -60,13 +59,5 @@ namespace SagaManager.Services return orderIds; } - - private void Publish(int orderId) - { - var confirmGracePeriodEvent = new ConfirmGracePeriodCommandMsg(orderId); - - // Publish through the Event Bus - _sagaManagerIntegrationEventService.PublishThroughEventBus(confirmGracePeriodEvent); - } } } \ No newline at end of file From 9b449461f23f6bc2e1693612839e2176004112b8 Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Wed, 17 May 2017 11:57:02 +0200 Subject: [PATCH 11/11] naming changes --- ...ler.cs => ConfirmOrderStockCommandHandler.cs} | 14 +++++++------- ...r.cs => DecrementOrderStockCommandHandler.cs} | 8 ++++---- ...CommandMsg.cs => ConfirmOrderStockCommand.cs} | 4 ++-- ...mmandMsg.cs => DecrementOrderStockCommand.cs} | 4 ++-- .../OrderStockNotConfirmedIntegrationEvent.cs | 6 +++--- src/Services/Catalog/Catalog.API/Startup.cs | 12 ++++++------ ...ngedToAwaitingValidationDomainEventHandler.cs | 6 +++--- ...OrderStatusChangedToPaidDomainEventHandler.cs | 6 +++--- ...sChangedToStockConfirmedDomainEventHandler.cs | 6 +++--- ...ommandMsg.cs => ConfirmGracePeriodCommand.cs} | 4 ++-- ...CommandMsg.cs => ConfirmOrderStockCommand.cs} | 4 ++-- ...mmandMsg.cs => DecrementOrderStockCommand.cs} | 4 ++-- ...{PayOrderCommandMsg.cs => PayOrderCommand.cs} | 4 ++-- .../Commands/ShipOrderCommandMsg.cs | 14 -------------- ...erStockNotConfirmedIntegrationEventHandler.cs | 2 +- .../OrderStockNotConfirmedIntegrationEvent.cs | 6 +++--- .../Application/Sagas/OrderProcessSaga.cs | 4 ++-- src/Services/Ordering/Ordering.API/Startup.cs | 4 ++-- ...ndMsgHandler.cs => PayOrderCommandHandler.cs} | 14 +++++--------- ...{PayOrderCommandMsg.cs => PayOrderCommand.cs} | 4 ++-- src/Services/Payment/Payment.API/Startup.cs | 16 +++++++++++----- ...ommandMsg.cs => ConfirmGracePeriodCommand.cs} | 4 ++-- src/Services/SagaManager/SagaManager/Program.cs | 2 +- .../SagaManager/Services/ISagaManagerService.cs | 2 +- .../SagaManager/Services/SagaManagerService.cs | 9 ++++----- 25 files changed, 75 insertions(+), 88 deletions(-) rename src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/{ConfirmOrderStockCommandMsgHandler.cs => ConfirmOrderStockCommandHandler.cs} (80%) rename src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/{DecrementOrderStockCommandMsgHandler.cs => DecrementOrderStockCommandHandler.cs} (66%) rename src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/{ConfirmOrderStockCommandMsg.cs => ConfirmOrderStockCommand.cs} (85%) rename src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/{DecrementOrderStockCommandMsg.cs => DecrementOrderStockCommand.cs} (79%) rename src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/{ConfirmGracePeriodCommandMsg.cs => ConfirmGracePeriodCommand.cs} (63%) rename src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/{ConfirmOrderStockCommandMsg.cs => ConfirmOrderStockCommand.cs} (85%) rename src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/{DecrementOrderStockCommandMsg.cs => DecrementOrderStockCommand.cs} (78%) rename src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/{PayOrderCommandMsg.cs => PayOrderCommand.cs} (69%) delete mode 100644 src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/ShipOrderCommandMsg.cs rename src/Services/Payment/Payment.API/IntegrationCommands/CommandHandlers/{PayOrderCommandMsgHandler.cs => PayOrderCommandHandler.cs} (71%) rename src/Services/Payment/Payment.API/IntegrationCommands/Commands/{PayOrderCommandMsg.cs => PayOrderCommand.cs} (58%) rename src/Services/SagaManager/SagaManager/IntegrationEvents/Events/{ConfirmGracePeriodCommandMsg.cs => ConfirmGracePeriodCommand.cs} (54%) diff --git a/src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/ConfirmOrderStockCommandMsgHandler.cs b/src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/ConfirmOrderStockCommandHandler.cs similarity index 80% rename from src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/ConfirmOrderStockCommandMsgHandler.cs rename to src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/ConfirmOrderStockCommandHandler.cs index beb23bbaf..7edfd5cf7 100644 --- a/src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/ConfirmOrderStockCommandMsgHandler.cs +++ b/src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/ConfirmOrderStockCommandHandler.cs @@ -12,23 +12,23 @@ using Commands; using IntegrationEvents.Events; - public class ConfirmOrderStockCommandMsgHandler : IIntegrationEventHandler + public class ConfirmOrderStockCommandHandler : IIntegrationEventHandler { private readonly CatalogContext _catalogContext; private readonly ICatalogIntegrationEventService _catalogIntegrationEventService; - public ConfirmOrderStockCommandMsgHandler(CatalogContext catalogContext, + public ConfirmOrderStockCommandHandler(CatalogContext catalogContext, ICatalogIntegrationEventService catalogIntegrationEventService) { _catalogContext = catalogContext; _catalogIntegrationEventService = catalogIntegrationEventService; } - public async Task Handle(ConfirmOrderStockCommandMsg @event) + public async Task Handle(ConfirmOrderStockCommand command) { var confirmedOrderStockItems = new List(); - foreach (var orderStockItem in @event.OrderStockItems) + foreach (var orderStockItem in command.OrderStockItems) { var catalogItem = _catalogContext.CatalogItems.Find(orderStockItem.ProductId); CheckValidcatalogItemId(catalogItem); @@ -39,9 +39,9 @@ confirmedOrderStockItems.Add(confirmedOrderStockItem); } - var confirmedIntegrationEvent = confirmedOrderStockItems.Any(c => !c.Confirmed) - ? (IntegrationEvent) new OrderStockNotConfirmedIntegrationEvent(@event.OrderId, confirmedOrderStockItems) - : new OrderStockConfirmedIntegrationEvent(@event.OrderId); + var confirmedIntegrationEvent = confirmedOrderStockItems.Any(c => !c.HasStock) + ? (IntegrationEvent) new OrderStockNotConfirmedIntegrationEvent(command.OrderId, confirmedOrderStockItems) + : new OrderStockConfirmedIntegrationEvent(command.OrderId); await _catalogIntegrationEventService.SaveEventAndCatalogContextChangesAsync(confirmedIntegrationEvent); await _catalogIntegrationEventService.PublishThroughEventBusAsync(confirmedIntegrationEvent); diff --git a/src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandMsgHandler.cs b/src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandHandler.cs similarity index 66% rename from src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandMsgHandler.cs rename to src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandHandler.cs index a6bc43228..1c7d1b9a3 100644 --- a/src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandMsgHandler.cs +++ b/src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandHandler.cs @@ -5,19 +5,19 @@ using Infrastructure; using Commands; - public class DecrementOrderStockCommandMsgHandler : IIntegrationEventHandler + public class DecrementOrderStockCommandHandler : IIntegrationEventHandler { private readonly CatalogContext _catalogContext; - public DecrementOrderStockCommandMsgHandler(CatalogContext catalogContext) + public DecrementOrderStockCommandHandler(CatalogContext catalogContext) { _catalogContext = catalogContext; } - public async Task Handle(DecrementOrderStockCommandMsg @event) + public async Task Handle(DecrementOrderStockCommand command) { //we're not blocking stock/inventory - foreach (var orderStockItem in @event.OrderStockItems) + foreach (var orderStockItem in command.OrderStockItems) { var catalogItem = _catalogContext.CatalogItems.Find(orderStockItem.ProductId); diff --git a/src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/ConfirmOrderStockCommandMsg.cs b/src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/ConfirmOrderStockCommand.cs similarity index 85% rename from src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/ConfirmOrderStockCommandMsg.cs rename to src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/ConfirmOrderStockCommand.cs index f5fc805b2..2c5296776 100644 --- a/src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/ConfirmOrderStockCommandMsg.cs +++ b/src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/ConfirmOrderStockCommand.cs @@ -3,12 +3,12 @@ using BuildingBlocks.EventBus.Events; using System.Collections.Generic; - public class ConfirmOrderStockCommandMsg : IntegrationEvent + public class ConfirmOrderStockCommand : IntegrationEvent { public int OrderId { get; } public IEnumerable OrderStockItems { get; } - public ConfirmOrderStockCommandMsg(int orderId, + public ConfirmOrderStockCommand(int orderId, IEnumerable orderStockItems) { OrderId = orderId; diff --git a/src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/DecrementOrderStockCommandMsg.cs b/src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/DecrementOrderStockCommand.cs similarity index 79% rename from src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/DecrementOrderStockCommandMsg.cs rename to src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/DecrementOrderStockCommand.cs index 94bab1aa6..ca241d6fd 100644 --- a/src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/DecrementOrderStockCommandMsg.cs +++ b/src/Services/Catalog/Catalog.API/IntegrationCommands/Commands/DecrementOrderStockCommand.cs @@ -3,12 +3,12 @@ using System.Collections.Generic; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; - public class DecrementOrderStockCommandMsg : IntegrationEvent + public class DecrementOrderStockCommand : IntegrationEvent { public int OrderId { get; } public IEnumerable OrderStockItems { get; } - public DecrementOrderStockCommandMsg(int orderId, + public DecrementOrderStockCommand(int orderId, IEnumerable orderStockItems) { OrderId = orderId; diff --git a/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs b/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs index be57329c7..b32b0dff5 100644 --- a/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs +++ b/src/Services/Catalog/Catalog.API/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs @@ -20,12 +20,12 @@ public class ConfirmedOrderStockItem { public int ProductId { get; } - public bool Confirmed { get; } + public bool HasStock { get; } - public ConfirmedOrderStockItem(int productId, bool confirmed) + public ConfirmedOrderStockItem(int productId, bool hasStock) { ProductId = productId; - Confirmed = confirmed; + HasStock = hasStock; } } } \ No newline at end of file diff --git a/src/Services/Catalog/Catalog.API/Startup.cs b/src/Services/Catalog/Catalog.API/Startup.cs index 1820e1f04..1f65e6a91 100644 --- a/src/Services/Catalog/Catalog.API/Startup.cs +++ b/src/Services/Catalog/Catalog.API/Startup.cs @@ -190,10 +190,10 @@ services.AddSingleton(); services.AddSingleton(); - services.AddTransient, - ConfirmOrderStockCommandMsgHandler>(); - services.AddTransient, - DecrementOrderStockCommandMsgHandler>(); + services.AddTransient, + ConfirmOrderStockCommandHandler>(); + services.AddTransient, + DecrementOrderStockCommandHandler>(); } @@ -201,8 +201,8 @@ { var eventBus = app.ApplicationServices.GetRequiredService(); - eventBus.Subscribe>(); - eventBus.Subscribe>(); + eventBus.Subscribe>(); + eventBus.Subscribe>(); } } } diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs index 06fd8bcfe..9a74d6a90 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs @@ -35,10 +35,10 @@ var orderStockList = orderStatusChangedToAwaitingValidationDomainEvent.OrderItems .Select(orderItem => new OrderStockItem(orderItem.ProductId, orderItem.GetUnits())); - var confirmOrderStockEvent = new ConfirmOrderStockCommandMsg(orderStatusChangedToAwaitingValidationDomainEvent.OrderId, + var confirmOrderStockCommand = new ConfirmOrderStockCommand(orderStatusChangedToAwaitingValidationDomainEvent.OrderId, orderStockList); - await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(confirmOrderStockEvent); - await _orderingIntegrationEventService.PublishThroughEventBusAsync(confirmOrderStockEvent); + await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(confirmOrderStockCommand); + await _orderingIntegrationEventService.PublishThroughEventBusAsync(confirmOrderStockCommand); } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs index ade15b149..300d5d75f 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs @@ -35,10 +35,10 @@ var orderStockList = orderStatusChangedToPaidDomainEvent.OrderItems .Select(orderItem => new OrderStockItem(orderItem.ProductId, orderItem.GetUnits())); - var decrementOrderStockCommandMsg = new DecrementOrderStockCommandMsg(orderStatusChangedToPaidDomainEvent.OrderId, + var decrementOrderStockCommand = new DecrementOrderStockCommand(orderStatusChangedToPaidDomainEvent.OrderId, orderStockList); - await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(decrementOrderStockCommandMsg); - await _orderingIntegrationEventService.PublishThroughEventBusAsync(decrementOrderStockCommandMsg); + await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(decrementOrderStockCommand); + await _orderingIntegrationEventService.PublishThroughEventBusAsync(decrementOrderStockCommand); } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs index 55b6d6c9a..272cbb061 100644 --- a/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs @@ -31,9 +31,9 @@ .LogTrace($"Order with Id: {orderStatusChangedToStockConfirmedDomainEvent.OrderId} has been successfully updated with " + $"a status order id: {OrderStatus.StockConfirmed.Id}"); - var payOrderCommandMsg = new PayOrderCommandMsg(orderStatusChangedToStockConfirmedDomainEvent.OrderId); - await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(payOrderCommandMsg); - await _orderingIntegrationEventService.PublishThroughEventBusAsync(payOrderCommandMsg); + var payOrderCommand = new PayOrderCommand(orderStatusChangedToStockConfirmedDomainEvent.OrderId); + await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(payOrderCommand); + await _orderingIntegrationEventService.PublishThroughEventBusAsync(payOrderCommand); } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/ConfirmGracePeriodCommandMsg.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/ConfirmGracePeriodCommand.cs similarity index 63% rename from src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/ConfirmGracePeriodCommandMsg.cs rename to src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/ConfirmGracePeriodCommand.cs index f9d8b8923..33b509f16 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/ConfirmGracePeriodCommandMsg.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/ConfirmGracePeriodCommand.cs @@ -2,11 +2,11 @@ namespace Ordering.API.Application.IntegrationCommands.Commands { - public class ConfirmGracePeriodCommandMsg : IntegrationEvent + public class ConfirmGracePeriodCommand : IntegrationEvent { public int OrderId { get; } - public ConfirmGracePeriodCommandMsg(int orderId) => + public ConfirmGracePeriodCommand(int orderId) => OrderId = orderId; } } diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/ConfirmOrderStockCommandMsg.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/ConfirmOrderStockCommand.cs similarity index 85% rename from src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/ConfirmOrderStockCommandMsg.cs rename to src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/ConfirmOrderStockCommand.cs index 6e78598f1..b3f73617c 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/ConfirmOrderStockCommandMsg.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/ConfirmOrderStockCommand.cs @@ -3,12 +3,12 @@ using System.Collections.Generic; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; - public class ConfirmOrderStockCommandMsg : IntegrationEvent + public class ConfirmOrderStockCommand : IntegrationEvent { public int OrderId { get; } public IEnumerable OrderStockItems { get; } - public ConfirmOrderStockCommandMsg(int orderId, + public ConfirmOrderStockCommand(int orderId, IEnumerable orderStockItems) { OrderId = orderId; diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/DecrementOrderStockCommandMsg.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/DecrementOrderStockCommand.cs similarity index 78% rename from src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/DecrementOrderStockCommandMsg.cs rename to src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/DecrementOrderStockCommand.cs index e05a20c48..3d0457ee8 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/DecrementOrderStockCommandMsg.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/DecrementOrderStockCommand.cs @@ -3,12 +3,12 @@ using System.Collections.Generic; using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; - public class DecrementOrderStockCommandMsg : IntegrationEvent + public class DecrementOrderStockCommand : IntegrationEvent { public int OrderId { get; } public IEnumerable OrderStockItems { get; } - public DecrementOrderStockCommandMsg(int orderId, + public DecrementOrderStockCommand(int orderId, IEnumerable orderStockItems) { OrderId = orderId; diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/PayOrderCommandMsg.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/PayOrderCommand.cs similarity index 69% rename from src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/PayOrderCommandMsg.cs rename to src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/PayOrderCommand.cs index 749ec882e..8a3ca665c 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/PayOrderCommandMsg.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/PayOrderCommand.cs @@ -2,11 +2,11 @@ { using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; - public class PayOrderCommandMsg : IntegrationEvent + public class PayOrderCommand : IntegrationEvent { public int OrderId { get; } - public PayOrderCommandMsg(int orderId) + public PayOrderCommand(int orderId) { OrderId = orderId; } diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/ShipOrderCommandMsg.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/ShipOrderCommandMsg.cs deleted file mode 100644 index 5a8695ae9..000000000 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationCommands/Commands/ShipOrderCommandMsg.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Ordering.API.Application.IntegrationCommands.Commands -{ - using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; - - public class ShipOrderCommandMsg : IntegrationEvent - { - public int OrderId { get; } - - public ShipOrderCommandMsg(int orderId) - { - OrderId = orderId; - } - } -} \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs index f3003c0a4..49708fe92 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs @@ -22,7 +22,7 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId); var orderStockNotConfirmedItems = @event.OrderStockItems - .FindAll(c => !c.Confirmed) + .FindAll(c => !c.HasStock) .Select(c => c.ProductId); orderToUpdate.SetStockConfirmedStatus(orderStockNotConfirmedItems); diff --git a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs index 5337c5eae..6bdb38ab2 100644 --- a/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs +++ b/src/Services/Ordering/Ordering.API/Application/IntegrationEvents/Events/OrderStockNotConfirmedIntegrationEvent.cs @@ -21,12 +21,12 @@ namespace Ordering.API.Application.IntegrationEvents.Events public class ConfirmedOrderStockItem { public int ProductId { get; } - public bool Confirmed { get; } + public bool HasStock { get; } - public ConfirmedOrderStockItem(int productId, bool confirmed) + public ConfirmedOrderStockItem(int productId, bool hasStock) { ProductId = productId; - Confirmed = confirmed; + HasStock = hasStock; } } } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs b/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs index 08b699a1f..a769c7e4c 100644 --- a/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs +++ b/src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs @@ -21,7 +21,7 @@ namespace Ordering.API.Application.Sagas /// with the validations. /// public class OrderProcessSaga : OrderSaga, - IIntegrationEventHandler, + IIntegrationEventHandler, IAsyncRequestHandler, IAsyncRequestHandler { @@ -43,7 +43,7 @@ namespace Ordering.API.Application.Sagas /// period has completed. /// /// - public async Task Handle(ConfirmGracePeriodCommandMsg command) + public async Task Handle(ConfirmGracePeriodCommand command) { var orderSaga = FindSagaById(command.OrderId); CheckValidSagaId(orderSaga); diff --git a/src/Services/Ordering/Ordering.API/Startup.cs b/src/Services/Ordering/Ordering.API/Startup.cs index 6f7828721..fc2bb90f2 100644 --- a/src/Services/Ordering/Ordering.API/Startup.cs +++ b/src/Services/Ordering/Ordering.API/Startup.cs @@ -171,7 +171,7 @@ services.AddSingleton(); services.AddTransient>(); - services.AddTransient, OrderProcessSaga>(); + services.AddTransient, OrderProcessSaga>(); services.AddTransient, OrderStockConfirmedIntegrationEventHandler>(); services.AddTransient, @@ -187,7 +187,7 @@ var eventBus = app.ApplicationServices.GetRequiredService(); eventBus.Subscribe>(); - eventBus.Subscribe>(); + eventBus.Subscribe>(); eventBus.Subscribe>(); eventBus.Subscribe>(); eventBus.Subscribe>(); diff --git a/src/Services/Payment/Payment.API/IntegrationCommands/CommandHandlers/PayOrderCommandMsgHandler.cs b/src/Services/Payment/Payment.API/IntegrationCommands/CommandHandlers/PayOrderCommandHandler.cs similarity index 71% rename from src/Services/Payment/Payment.API/IntegrationCommands/CommandHandlers/PayOrderCommandMsgHandler.cs rename to src/Services/Payment/Payment.API/IntegrationCommands/CommandHandlers/PayOrderCommandHandler.cs index 178b36474..ea1398cf8 100644 --- a/src/Services/Payment/Payment.API/IntegrationCommands/CommandHandlers/PayOrderCommandMsgHandler.cs +++ b/src/Services/Payment/Payment.API/IntegrationCommands/CommandHandlers/PayOrderCommandHandler.cs @@ -3,21 +3,17 @@ using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; using Payment.API.IntegrationCommands.Commands; using System.Threading.Tasks; - using System; using Payment.API.IntegrationEvents; using Payment.API.IntegrationEvents.Events; - public class PayOrderCommandMsgHandler : IIntegrationEventHandler + public class PayOrderCommandHandler : IIntegrationEventHandler { private readonly IPaymentIntegrationEventService _paymentIntegrationEventService; - public PayOrderCommandMsgHandler(IPaymentIntegrationEventService paymentIntegrationEventService) - { - _paymentIntegrationEventService = paymentIntegrationEventService; - } - + public PayOrderCommandHandler(IPaymentIntegrationEventService paymentIntegrationEventService) + => _paymentIntegrationEventService = paymentIntegrationEventService; - public async Task Handle(PayOrderCommandMsg @event) + public async Task Handle(PayOrderCommand @event) { //PAYMENT SUCCESSED var orderPaymentSuccededIntegrationEvent = new OrderPaymentSuccededIntegrationEvent(@event.OrderId); @@ -28,4 +24,4 @@ //_paymentIntegrationEventService.PublishThroughEventBus(orderPaymentFailedIntegrationEvent); } } -} +} \ No newline at end of file diff --git a/src/Services/Payment/Payment.API/IntegrationCommands/Commands/PayOrderCommandMsg.cs b/src/Services/Payment/Payment.API/IntegrationCommands/Commands/PayOrderCommand.cs similarity index 58% rename from src/Services/Payment/Payment.API/IntegrationCommands/Commands/PayOrderCommandMsg.cs rename to src/Services/Payment/Payment.API/IntegrationCommands/Commands/PayOrderCommand.cs index 360f40606..d6476fa6e 100644 --- a/src/Services/Payment/Payment.API/IntegrationCommands/Commands/PayOrderCommandMsg.cs +++ b/src/Services/Payment/Payment.API/IntegrationCommands/Commands/PayOrderCommand.cs @@ -2,10 +2,10 @@ { using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; - public class PayOrderCommandMsg : IntegrationEvent + public class PayOrderCommand : IntegrationEvent { public int OrderId { get; } - public PayOrderCommandMsg(int orderId) => OrderId = orderId; + public PayOrderCommand(int orderId) => OrderId = orderId; } } \ No newline at end of file diff --git a/src/Services/Payment/Payment.API/Startup.cs b/src/Services/Payment/Payment.API/Startup.cs index eaef3f704..e7a47f766 100644 --- a/src/Services/Payment/Payment.API/Startup.cs +++ b/src/Services/Payment/Payment.API/Startup.cs @@ -48,10 +48,8 @@ namespace Payment.API return new DefaultRabbitMQPersistentConnection(factory, logger); }); - services.AddSingleton(); - services.AddSingleton(); - services.AddTransient, PayOrderCommandMsgHandler>(); - + + RegisterServiceBus(services); services.AddSwaggerGen(); services.ConfigureSwaggerGen(options => @@ -85,10 +83,18 @@ namespace Payment.API ConfigureEventBus(app); } + private void RegisterServiceBus(IServiceCollection services) + { + services.AddSingleton(); + services.AddSingleton(); + + services.AddTransient, PayOrderCommandHandler>(); + } + private void ConfigureEventBus(IApplicationBuilder app) { var eventBus = app.ApplicationServices.GetRequiredService(); - eventBus.Subscribe>(); + eventBus.Subscribe>(); } } } diff --git a/src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommandMsg.cs b/src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommand.cs similarity index 54% rename from src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommandMsg.cs rename to src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommand.cs index 6521cd200..fd507a265 100644 --- a/src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommandMsg.cs +++ b/src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommand.cs @@ -2,10 +2,10 @@ { using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; - public class ConfirmGracePeriodCommandMsg : IntegrationEvent + public class ConfirmGracePeriodCommand : IntegrationEvent { public int OrderId { get;} - public ConfirmGracePeriodCommandMsg(int orderId) => OrderId = orderId; + public ConfirmGracePeriodCommand(int orderId) => OrderId = orderId; } } \ No newline at end of file diff --git a/src/Services/SagaManager/SagaManager/Program.cs b/src/Services/SagaManager/SagaManager/Program.cs index c285dfa76..97784fc85 100644 --- a/src/Services/SagaManager/SagaManager/Program.cs +++ b/src/Services/SagaManager/SagaManager/Program.cs @@ -37,7 +37,7 @@ while (true) { - sagaManagerService.CheckFinishedGracePeriodOrders(); + sagaManagerService.CheckConfirmedGracePeriodOrders(); await Task.Delay(90000); } } diff --git a/src/Services/SagaManager/SagaManager/Services/ISagaManagerService.cs b/src/Services/SagaManager/SagaManager/Services/ISagaManagerService.cs index dc027b29c..6ee012c37 100644 --- a/src/Services/SagaManager/SagaManager/Services/ISagaManagerService.cs +++ b/src/Services/SagaManager/SagaManager/Services/ISagaManagerService.cs @@ -2,6 +2,6 @@ { public interface ISagaManagerService { - void CheckFinishedGracePeriodOrders(); + void CheckConfirmedGracePeriodOrders(); } } \ No newline at end of file diff --git a/src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs b/src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs index 7ef5ae25a..f7455e27c 100644 --- a/src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs +++ b/src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs @@ -23,19 +23,18 @@ _logger = logger; } - public void CheckFinishedGracePeriodOrders() + public void CheckConfirmedGracePeriodOrders() { - var orderIds = GetFinishedGracePeriodOrders(); + var orderIds = GetConfirmedGracePeriodOrders(); foreach (var orderId in orderIds) { - var confirmGracePeriodEvent = new ConfirmGracePeriodCommandMsg(orderId); - + var confirmGracePeriodEvent = new ConfirmGracePeriodCommand(orderId); _sagaManagerIntegrationEventService.PublishThroughEventBus(confirmGracePeriodEvent); } } - private IEnumerable GetFinishedGracePeriodOrders() + private IEnumerable GetConfirmedGracePeriodOrders() { IEnumerable orderIds = new List(); using (var conn = new SqlConnection(_settings.ConnectionString))