From 1a9adad2f4fbb9d487bef5a91bf17a453df04fbb Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Tue, 9 May 2017 13:56:20 +0200 Subject: [PATCH] Standard names fix --- .../ConfirmGracePeriodEvent.cs | 16 --------- ...ent.cs => ConfirmGracePeriodCommandMsg.cs} | 4 +-- .../IConfirmGracePeriodEvent.cs | 9 ----- .../ISagaManagingIntegrationEventService.cs | 10 ++++++ .../SagaManagingIntegrationEventService.cs | 35 +++++++++++++++++++ .../SagaManager/SagaManager/Program.cs | 2 +- .../SagaManager/SagaManager.csproj | 2 ++ .../Services/SagaManagerService.cs | 13 +++---- 8 files changed, 57 insertions(+), 34 deletions(-) delete mode 100644 src/Services/SagaManager/SagaManager/IntegrationEvents/ConfirmGracePeriodEvent.cs rename src/Services/SagaManager/SagaManager/IntegrationEvents/Events/{ConfirmGracePeriodIntegrationEvent.cs => ConfirmGracePeriodCommandMsg.cs} (73%) delete mode 100644 src/Services/SagaManager/SagaManager/IntegrationEvents/IConfirmGracePeriodEvent.cs create mode 100644 src/Services/SagaManager/SagaManager/IntegrationEvents/ISagaManagingIntegrationEventService.cs create mode 100644 src/Services/SagaManager/SagaManager/IntegrationEvents/SagaManagingIntegrationEventService.cs diff --git a/src/Services/SagaManager/SagaManager/IntegrationEvents/ConfirmGracePeriodEvent.cs b/src/Services/SagaManager/SagaManager/IntegrationEvents/ConfirmGracePeriodEvent.cs deleted file mode 100644 index 36f88c9be..000000000 --- a/src/Services/SagaManager/SagaManager/IntegrationEvents/ConfirmGracePeriodEvent.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace SagaManager.IntegrationEvents -{ - using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; - using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; - using System; - - public class ConfirmGracePeriodEvent : IConfirmGracePeriodEvent - { - private readonly IEventBus _eventBus; - - public ConfirmGracePeriodEvent(IEventBus eventBus) => - _eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus)); - - public void PublishThroughEventBus(IntegrationEvent evt) => _eventBus.Publish(evt); - } -} \ No newline at end of file diff --git a/src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodIntegrationEvent.cs b/src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommandMsg.cs similarity index 73% rename from src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodIntegrationEvent.cs rename to src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommandMsg.cs index 680328301..fc47f44e5 100644 --- a/src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodIntegrationEvent.cs +++ b/src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommandMsg.cs @@ -5,10 +5,10 @@ // 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 ConfirmGracePeriodIntegrationEvent : IntegrationEvent + public class ConfirmGracePeriodCommandMsg : IntegrationEvent { public int OrderId { get;} - public ConfirmGracePeriodIntegrationEvent(int orderId) => OrderId = orderId; + public ConfirmGracePeriodCommandMsg(int orderId) => OrderId = orderId; } } diff --git a/src/Services/SagaManager/SagaManager/IntegrationEvents/IConfirmGracePeriodEvent.cs b/src/Services/SagaManager/SagaManager/IntegrationEvents/IConfirmGracePeriodEvent.cs deleted file mode 100644 index 236860db2..000000000 --- a/src/Services/SagaManager/SagaManager/IntegrationEvents/IConfirmGracePeriodEvent.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace SagaManager.IntegrationEvents -{ - using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; - - public interface IConfirmGracePeriodEvent - { - void PublishThroughEventBus(IntegrationEvent evt); - } -} \ No newline at end of file diff --git a/src/Services/SagaManager/SagaManager/IntegrationEvents/ISagaManagingIntegrationEventService.cs b/src/Services/SagaManager/SagaManager/IntegrationEvents/ISagaManagingIntegrationEventService.cs new file mode 100644 index 000000000..d1eb3cb5d --- /dev/null +++ b/src/Services/SagaManager/SagaManager/IntegrationEvents/ISagaManagingIntegrationEventService.cs @@ -0,0 +1,10 @@ +namespace SagaManager.IntegrationEvents +{ + using System.Threading.Tasks; + using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; + + public interface ISagaManagingIntegrationEventService + { + Task PublishThroughEventBusAsync(IntegrationEvent evt); + } +} \ No newline at end of file diff --git a/src/Services/SagaManager/SagaManager/IntegrationEvents/SagaManagingIntegrationEventService.cs b/src/Services/SagaManager/SagaManager/IntegrationEvents/SagaManagingIntegrationEventService.cs new file mode 100644 index 000000000..c040143ad --- /dev/null +++ b/src/Services/SagaManager/SagaManager/IntegrationEvents/SagaManagingIntegrationEventService.cs @@ -0,0 +1,35 @@ +namespace SagaManager.IntegrationEvents +{ + using System.Data.Common; + using System.Threading.Tasks; + using Microsoft.EntityFrameworkCore; + using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; + using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events; + using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services; + using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure; + using System; + + public class SagaManagingIntegrationEventService : ISagaManagingIntegrationEventService + { + private readonly Func _integrationEventLogServiceFactory; + private readonly IEventBus _eventBus; + private readonly OrderingContext _orderingContext; + private readonly IIntegrationEventLogService _eventLogService; + + public SagaManagingIntegrationEventService(IEventBus eventBus, OrderingContext orderingContext, + Func integrationEventLogServiceFactory) + { + _orderingContext = orderingContext ?? throw new ArgumentNullException(nameof(orderingContext)); + _integrationEventLogServiceFactory = integrationEventLogServiceFactory ?? throw new ArgumentNullException(nameof(integrationEventLogServiceFactory)); + _eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus)); + _eventLogService = _integrationEventLogServiceFactory(_orderingContext.Database.GetDbConnection()); + } + + public async Task PublishThroughEventBusAsync(IntegrationEvent evt) + { + _eventBus.Publish(evt); + + await _eventLogService.MarkEventAsPublishedAsync(evt); + } + } +} \ No newline at end of file diff --git a/src/Services/SagaManager/SagaManager/Program.cs b/src/Services/SagaManager/SagaManager/Program.cs index 55e449e83..2152a046e 100644 --- a/src/Services/SagaManager/SagaManager/Program.cs +++ b/src/Services/SagaManager/SagaManager/Program.cs @@ -55,7 +55,7 @@ namespace SagaManager .AddOptions() .Configure(Configuration) .AddSingleton() - .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton(sp => diff --git a/src/Services/SagaManager/SagaManager/SagaManager.csproj b/src/Services/SagaManager/SagaManager/SagaManager.csproj index 47b8b58c2..ed76ff6d8 100644 --- a/src/Services/SagaManager/SagaManager/SagaManager.csproj +++ b/src/Services/SagaManager/SagaManager/SagaManager.csproj @@ -21,6 +21,8 @@ + + diff --git a/src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs b/src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs index 7445ca090..32743df03 100644 --- a/src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs +++ b/src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Microsoft.Extensions.Logging; namespace SagaManager.Services @@ -13,15 +14,15 @@ namespace SagaManager.Services public class SagaManagerService : ISagaManagerService { private readonly SagaManagerSettings _settings; - private readonly IConfirmGracePeriodEvent _confirmGracePeriodEvent; + private readonly ISagaManagingIntegrationEventService _sagaManagingIntegrationEventService; private readonly ILogger _logger; public SagaManagerService(IOptions settings, - IConfirmGracePeriodEvent confirmGracePeriodEvent, + ISagaManagingIntegrationEventService sagaManagingIntegrationEventService, ILogger logger) { _settings = settings.Value; - _confirmGracePeriodEvent = confirmGracePeriodEvent; + _sagaManagingIntegrationEventService = sagaManagingIntegrationEventService; _logger = logger; } @@ -59,12 +60,12 @@ namespace SagaManager.Services return orderIds; } - private void Publish(int orderId) + private async Task Publish(int orderId) { - var confirmGracePeriodEvent = new ConfirmGracePeriodIntegrationEvent(orderId); + var confirmGracePeriodEvent = new ConfirmGracePeriodCommandMsg(orderId); // Publish through the Event Bus - _confirmGracePeriodEvent.PublishThroughEventBus(confirmGracePeriodEvent); + await _sagaManagingIntegrationEventService.PublishThroughEventBusAsync(confirmGracePeriodEvent); } } } \ No newline at end of file