Browse Source

minor changes

pull/223/head
Christian Arenas 7 years ago
parent
commit
8b80eeae52
18 changed files with 67 additions and 114 deletions
  1. +0
    -6
      src/Services/Basket/Basket.API/Startup.cs
  2. +0
    -3
      src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandMsgHandler.cs
  3. +13
    -4
      src/Services/Catalog/Catalog.API/Startup.cs
  4. +1
    -1
      src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs
  5. +0
    -2
      src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs
  6. +0
    -2
      src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs
  7. +0
    -2
      src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs
  8. +1
    -1
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs
  9. +1
    -1
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs
  10. +1
    -1
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs
  11. +1
    -1
      src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs
  12. +8
    -20
      src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs
  13. +18
    -14
      src/Services/Ordering/Ordering.API/Startup.cs
  14. +3
    -11
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs
  15. +1
    -4
      src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommandMsg.cs
  16. +3
    -7
      src/Services/SagaManager/SagaManager/IntegrationEvents/SagaManagerIntegrationEventService.cs
  17. +11
    -20
      src/Services/SagaManager/SagaManager/Program.cs
  18. +5
    -14
      src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs

+ 0
- 6
src/Services/Basket/Basket.API/Startup.cs View File

@ -165,12 +165,6 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
protected virtual void ConfigureEventBus(IApplicationBuilder app)
{
var catalogPriceHandler = app.ApplicationServices
.GetService<IIntegrationEventHandler<ProductPriceChangedIntegrationEvent>>();
var orderStartedHandler = app.ApplicationServices
.GetService<IIntegrationEventHandler<OrderStartedIntegrationEvent>>();
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
eventBus.Subscribe<ProductPriceChangedIntegrationEvent, ProductPriceChangedIntegrationEventHandler>();


+ 0
- 3
src/Services/Catalog/Catalog.API/IntegrationCommands/CommandHandlers/DecrementOrderStockCommandMsgHandler.cs View File

@ -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<DecrementOrderStockCommandMsg>


+ 13
- 4
src/Services/Catalog/Catalog.API/Startup.cs View File

@ -121,10 +121,7 @@
return new DefaultRabbitMQPersistentConnection(factory, logger);
});
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
services.AddTransient<IIntegrationEventHandler<ConfirmOrderStockCommandMsg>, ConfirmOrderStockCommandMsgHandler>();
services.AddTransient<IIntegrationEventHandler<DecrementOrderStockCommandMsg>, DecrementOrderStockCommandMsgHandler>();
RegisterServiceBus(services);
var container = new ContainerBuilder();
container.Populate(services);
@ -188,6 +185,18 @@
}
}
private void RegisterServiceBus(IServiceCollection services)
{
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
services.AddTransient<IIntegrationEventHandler<ConfirmOrderStockCommandMsg>,
ConfirmOrderStockCommandMsgHandler>();
services.AddTransient<IIntegrationEventHandler<DecrementOrderStockCommandMsg>,
DecrementOrderStockCommandMsgHandler>();
}
private void ConfigureEventBus(IApplicationBuilder app)
{
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();


+ 1
- 1
src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommandHandler.cs View File

@ -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);


+ 0
- 2
src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderGracePeriodConfirmed/OrderStatusChangedToAwaitingValidationDomainEventHandler.cs View File

@ -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}");


+ 0
- 2
src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderPaid/OrderStatusChangedToPaidDomainEventHandler.cs View File

@ -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}");


+ 0
- 2
src/Services/Ordering/Ordering.API/Application/DomainEventHandlers/OrderStockConfirmed/OrderStatusChangedToStockConfirmedDomainEventHandler.cs View File

@ -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}");


+ 1
- 1
src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentFailedIntegrationEventHandler.cs View File

@ -21,7 +21,7 @@
orderToUpdate.SetCancelledStatus();
await _orderRepository.UnitOfWork.SaveChangesAsync();
await _orderRepository.UnitOfWork.SaveEntitiesAsync();
}
}
}

+ 1
- 1
src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderPaymentSuccededIntegrationEventHandler.cs View File

@ -21,7 +21,7 @@
orderToUpdate.SetPaidStatus();
await _orderRepository.UnitOfWork.SaveChangesAsync();
await _orderRepository.UnitOfWork.SaveEntitiesAsync();
}
}
}

+ 1
- 1
src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockConfirmedIntegrationEventHandler.cs View File

@ -21,7 +21,7 @@
orderToUpdate.SetStockConfirmedStatus();
await _orderRepository.UnitOfWork.SaveChangesAsync();
await _orderRepository.UnitOfWork.SaveEntitiesAsync();
}
}
}

+ 1
- 1
src/Services/Ordering/Ordering.API/Application/IntegrationEvents/EventHandling/OrderStockNotConfirmedIntegrationEventHandler.cs View File

@ -27,7 +27,7 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
orderToUpdate.SetStockConfirmedStatus(orderStockNotConfirmedItems);
await _orderRepository.UnitOfWork.SaveChangesAsync();
await _orderRepository.UnitOfWork.SaveEntitiesAsync();
}
}
}

+ 8
- 20
src/Services/Ordering/Ordering.API/Application/Sagas/OrderProcessSaga.cs View File

@ -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();
}
/// <summary>
@ -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;
}


+ 18
- 14
src/Services/Ordering/Ordering.API/Startup.cs View File

@ -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<IEventBus, EventBusRabbitMQ>();
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
services.AddTransient<IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
services.AddTransient<IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>, OrderProcessSaga>();
services.AddTransient<IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>,
OrderStockConfirmedIntegrationEventHandler>();
services.AddTransient<IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>,
OrderStockNotConfirmedIntegrationEventHandler>();
services.AddTransient<IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent>,
OrderPaymentFailedIntegrationEventHandler>();
services.AddTransient<IIntegrationEventHandler<OrderPaymentSuccededIntegrationEvent>,
OrderPaymentSuccededIntegrationEventHandler>();
RegisterServiceBus(services);
services.AddOptions();
//configure autofac
@ -178,6 +165,23 @@
}
private void RegisterServiceBus(IServiceCollection services)
{
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
services.AddTransient<IIntegrationEventHandler<UserCheckoutAcceptedIntegrationEvent>>();
services.AddTransient<IIntegrationEventHandler<ConfirmGracePeriodCommandMsg>, OrderProcessSaga>();
services.AddTransient<IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>,
OrderStockConfirmedIntegrationEventHandler>();
services.AddTransient<IIntegrationEventHandler<OrderStockNotConfirmedIntegrationEvent>,
OrderStockNotConfirmedIntegrationEventHandler>();
services.AddTransient<IIntegrationEventHandler<OrderPaymentFailedIntegrationEvent>,
OrderPaymentFailedIntegrationEventHandler>();
services.AddTransient<IIntegrationEventHandler<OrderPaymentSuccededIntegrationEvent>,
OrderPaymentSuccededIntegrationEventHandler>();
}
private void ConfigureEventBus(IApplicationBuilder app)
{
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();


+ 3
- 11
src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs View File

@ -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)
{


+ 1
- 4
src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommandMsg.cs View File

@ -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;
}
}
}

+ 3
- 7
src/Services/SagaManager/SagaManager/IntegrationEvents/SagaManagerIntegrationEventService.cs View File

@ -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);
}
}

+ 11
- 20
src/Services/SagaManager/SagaManager/Program.cs View File

@ -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<SagaManagerSettings>(Configuration)
.AddSingleton<ISagaManagerService, SagaManagerService>()
.AddSingleton<ISagaManagerIntegrationEventService, SagaManagerIntegrationEventService>()
.AddSingleton<IEventBus, EventBusRabbitMQ>()
.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>()
.AddSingleton<IRabbitMQPersistentConnection>(sp =>
{
var settings = sp.GetRequiredService<IOptions<SagaManagerSettings>>().Value;
@ -78,8 +70,7 @@ namespace SagaManager
};
return new DefaultRabbitMQPersistentConnection(factory, logger);
})
.AddSingleton<IEventBus, EventBusRabbitMQ>();
});
RegisterServiceBus(services);


+ 5
- 14
src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs View File

@ -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);
}
}
}

Loading…
Cancel
Save