Skip to content

Commit 3556a5d

Browse files
committed
Change SaveEntitiesAsync to SaveChangesAsync
1 parent aaa821b commit 3556a5d

9 files changed

Lines changed: 26 additions & 18 deletions

File tree

src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ public async Task Handle(OrderStatusChangedToPaidDomainEvent orderStatusChangedT
4141
orderStockList);
4242
await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(decrementOrderStockCommandMsg);
4343
await _orderingIntegrationEventService.PublishThroughEventBusAsync(decrementOrderStockCommandMsg);
44-
45-
//is it necessary get a DecrementOrderStockSuccessIntegrationEvent/DecrementOrderStockFailedIntegrationEvent before to call ShipOrderCommandMsg???
46-
var shipOrderCommandMsg = new ShipOrderCommandMsg(orderStatusChangedToPaidDomainEvent.OrderId);
47-
await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(shipOrderCommandMsg);
48-
await _orderingIntegrationEventService.PublishThroughEventBusAsync(shipOrderCommandMsg);
4944
}
5045
}
5146
}

src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public OrderPaymentFailedIntegrationEventHandler(IOrderRepository orderRepositor
1717

1818
public async Task Handle(OrderPaymentFailedIntegrationEvent @event)
1919
{
20-
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
20+
var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId);
2121

2222
orderToUpdate.SetCancelledStatus();
2323

24-
await _orderRepository.UnitOfWork.SaveEntitiesAsync();
24+
await _orderRepository.UnitOfWork.SaveChangesAsync();
2525
}
2626
}
2727
}

src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public OrderPaymentSuccededIntegrationEventHandler(IOrderRepository orderReposit
1717

1818
public async Task Handle(OrderPaymentSuccededIntegrationEvent @event)
1919
{
20-
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
20+
var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId);
2121

2222
orderToUpdate.SetPaidStatus();
2323

24-
await _orderRepository.UnitOfWork.SaveEntitiesAsync();
24+
await _orderRepository.UnitOfWork.SaveChangesAsync();
2525
}
2626
}
2727
}

src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public OrderStockConfirmedIntegrationEventHandler(IOrderRepository orderReposito
1717

1818
public async Task Handle(OrderStockConfirmedIntegrationEvent @event)
1919
{
20-
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
20+
var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId);
2121

2222
orderToUpdate.SetStockConfirmedStatus();
2323

24-
await _orderRepository.UnitOfWork.SaveEntitiesAsync();
24+
await _orderRepository.UnitOfWork.SaveChangesAsync();
2525
}
2626
}
2727
}

src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public OrderStockNotConfirmedIntegrationEventHandler(IOrderRepository orderRepos
1919

2020
public async Task Handle(OrderStockNotConfirmedIntegrationEvent @event)
2121
{
22-
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId);
22+
var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId);
2323

2424
var orderStockNotConfirmedItems = @event.OrderStockItems
2525
.FindAll(c => !c.Confirmed)

src/Services/Ordering/Ordering.API/Startup.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
using System;
3333
using System.Data.Common;
3434
using System.Reflection;
35+
using global::Ordering.API.Application.IntegrationEvents.EventHandling;
3536

3637
public class Startup
3738
{
@@ -129,8 +130,14 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
129130
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
130131
services.AddTransient<IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
131132
services.AddTransient<IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>, OrderProcessSaga>();
132-
services.AddTransient<IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>>();
133-
services.AddTransient<IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>>();
133+
services.AddTransient<IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>,
134+
OrderStockConfirmedIntegrationEventHandler>();
135+
services.AddTransient<IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>,
136+
OrderStockNotConfirmedIntegrationEventHandler>();
137+
services.AddTransient<IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent>,
138+
OrderPaymentFailedIntegrationEventHandler>();
139+
services.AddTransient<IIntegrationEventHandler<OrderPaymentSuccededIntegrationEvent>,
140+
OrderPaymentSuccededIntegrationEventHandler>();
134141
services.AddOptions();
135142

136143
//configure autofac
@@ -176,12 +183,11 @@ private void ConfigureEventBus(IApplicationBuilder app)
176183
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
177184

178185
eventBus.Subscribe<UserCheckoutAcceptedIntegrationEvent, IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
179-
180186
eventBus.Subscribe<ConfirmGracePeriodCommandMsg, IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>>();
181-
182187
eventBus.Subscribe<OrderStockConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>>();
183-
184188
eventBus.Subscribe<OrderStockNotConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>>();
189+
eventBus.Subscribe<OrderPaymentFailedIntegrationEvent, IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent>>();
190+
eventBus.Subscribe<OrderPaymentSuccededIntegrationEvent, IIntegrationEventHandler<OrderPaymentSuccededIntegrationEvent>>();
185191
}
186192

187193
protected virtual void ConfigureAuth(IApplicationBuilder app)

src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/IOrderRepository.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ public interface IOrderRepository : IRepository<Order>
1313
void Update(Order order);
1414

1515
Task<Order> GetAsync(int orderId);
16+
17+
Task<Order> GetWithDependenciesAsync(int orderId);
1618
}
1719
}

src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class Order
3030
// but only through the method OrderAggrergateRoot.AddOrderItem() which includes behaviour.
3131
private readonly List<OrderItem> _orderItems;
3232

33-
public IReadOnlyList<OrderItem> OrderItems => _orderItems;
33+
public IReadOnlyCollection<OrderItem> OrderItems => _orderItems;
3434
// Using List<>.AsReadOnly()
3535
// This will create a read only wrapper around the private list so is protected against "external updates".
3636
// 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)

src/Services/Ordering/Ordering.Infrastructure/Repositories/OrderRepository.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public Order Add(Order order)
3232
}
3333

3434
public async Task<Order> GetAsync(int orderId)
35+
{
36+
return await _context.Orders.FindAsync(orderId);
37+
}
38+
39+
public async Task<Order> GetWithDependenciesAsync(int orderId)
3540
{
3641
return await _context.Orders
3742
.Include(c => c.OrderStatus)

0 commit comments

Comments
 (0)