Change SaveEntitiesAsync to SaveChangesAsync

This commit is contained in:
Christian Arenas 2017-05-16 18:40:34 +02:00
parent dcec42a088
commit b95bf247cf
9 changed files with 26 additions and 18 deletions

View File

@ -41,11 +41,6 @@
orderStockList); orderStockList);
await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(decrementOrderStockCommandMsg); await _orderingIntegrationEventService.SaveEventAndOrderingContextChangesAsync(decrementOrderStockCommandMsg);
await _orderingIntegrationEventService.PublishThroughEventBusAsync(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);
} }
} }
} }

View File

@ -17,11 +17,11 @@
public async Task Handle(OrderPaymentFailedIntegrationEvent @event) public async Task Handle(OrderPaymentFailedIntegrationEvent @event)
{ {
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId); var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId);
orderToUpdate.SetCancelledStatus(); orderToUpdate.SetCancelledStatus();
await _orderRepository.UnitOfWork.SaveEntitiesAsync(); await _orderRepository.UnitOfWork.SaveChangesAsync();
} }
} }
} }

View File

@ -17,11 +17,11 @@
public async Task Handle(OrderPaymentSuccededIntegrationEvent @event) public async Task Handle(OrderPaymentSuccededIntegrationEvent @event)
{ {
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId); var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId);
orderToUpdate.SetPaidStatus(); orderToUpdate.SetPaidStatus();
await _orderRepository.UnitOfWork.SaveEntitiesAsync(); await _orderRepository.UnitOfWork.SaveChangesAsync();
} }
} }
} }

View File

@ -17,11 +17,11 @@
public async Task Handle(OrderStockConfirmedIntegrationEvent @event) public async Task Handle(OrderStockConfirmedIntegrationEvent @event)
{ {
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId); var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId);
orderToUpdate.SetStockConfirmedStatus(); orderToUpdate.SetStockConfirmedStatus();
await _orderRepository.UnitOfWork.SaveEntitiesAsync(); await _orderRepository.UnitOfWork.SaveChangesAsync();
} }
} }
} }

View File

@ -19,7 +19,7 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
public async Task Handle(OrderStockNotConfirmedIntegrationEvent @event) public async Task Handle(OrderStockNotConfirmedIntegrationEvent @event)
{ {
var orderToUpdate = await _orderRepository.GetAsync(@event.OrderId); var orderToUpdate = await _orderRepository.GetWithDependenciesAsync(@event.OrderId);
var orderStockNotConfirmedItems = @event.OrderStockItems var orderStockNotConfirmedItems = @event.OrderStockItems
.FindAll(c => !c.Confirmed) .FindAll(c => !c.Confirmed)

View File

@ -32,6 +32,7 @@
using System; using System;
using System.Data.Common; using System.Data.Common;
using System.Reflection; using System.Reflection;
using global::Ordering.API.Application.IntegrationEvents.EventHandling;
public class Startup public class Startup
{ {
@ -129,8 +130,14 @@
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>(); services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
services.AddTransient<IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>(); services.AddTransient<IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
services.AddTransient<IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>, OrderProcessSaga>(); services.AddTransient<IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>, OrderProcessSaga>();
services.AddTransient<IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>>(); services.AddTransient<IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>,
services.AddTransient<IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>>(); OrderStockConfirmedIntegrationEventHandler>();
services.AddTransient<IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>,
OrderStockNotConfirmedIntegrationEventHandler>();
services.AddTransient<IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent>,
OrderPaymentFailedIntegrationEventHandler>();
services.AddTransient<IIntegrationEventHandler<OrderPaymentSuccededIntegrationEvent>,
OrderPaymentSuccededIntegrationEventHandler>();
services.AddOptions(); services.AddOptions();
//configure autofac //configure autofac
@ -176,12 +183,11 @@
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>(); var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
eventBus.Subscribe<UserCheckoutAcceptedIntegrationEvent, IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>(); eventBus.Subscribe<UserCheckoutAcceptedIntegrationEvent, IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
eventBus.Subscribe<ConfirmGracePeriodCommandMsg, IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>>(); eventBus.Subscribe<ConfirmGracePeriodCommandMsg, IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>>();
eventBus.Subscribe<OrderStockConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>>(); eventBus.Subscribe<OrderStockConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>>();
eventBus.Subscribe<OrderStockNotConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>>(); eventBus.Subscribe<OrderStockNotConfirmedIntegrationEvent, IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>>();
eventBus.Subscribe<OrderPaymentFailedIntegrationEvent, IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent>>();
eventBus.Subscribe<OrderPaymentSuccededIntegrationEvent, IIntegrationEventHandler<OrderPaymentSuccededIntegrationEvent>>();
} }
protected virtual void ConfigureAuth(IApplicationBuilder app) protected virtual void ConfigureAuth(IApplicationBuilder app)

View File

@ -13,5 +13,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
void Update(Order order); void Update(Order order);
Task<Order> GetAsync(int orderId); Task<Order> GetAsync(int orderId);
Task<Order> GetWithDependenciesAsync(int orderId);
} }
} }

View File

@ -30,7 +30,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
// but only through the method OrderAggrergateRoot.AddOrderItem() which includes behaviour. // but only through the method OrderAggrergateRoot.AddOrderItem() which includes behaviour.
private readonly List<OrderItem> _orderItems; private readonly List<OrderItem> _orderItems;
public IReadOnlyList<OrderItem> OrderItems => _orderItems; public IReadOnlyCollection<OrderItem> OrderItems => _orderItems;
// Using List<>.AsReadOnly() // Using List<>.AsReadOnly()
// This will create a read only wrapper around the private list so is protected against "external updates". // 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) // 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)

View File

@ -32,6 +32,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor
} }
public async Task<Order> GetAsync(int orderId) public async Task<Order> GetAsync(int orderId)
{
return await _context.Orders.FindAsync(orderId);
}
public async Task<Order> GetWithDependenciesAsync(int orderId)
{ {
return await _context.Orders return await _context.Orders
.Include(c => c.OrderStatus) .Include(c => c.OrderStatus)