Skip to content

Commit d7bf2c9

Browse files
committed
Standard names fix
1 parent 4371e48 commit d7bf2c9

8 files changed

Lines changed: 57 additions & 34 deletions

File tree

src/Services/SagaManager/SagaManager/IntegrationEvents/ConfirmGracePeriodEvent.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodIntegrationEvent.cs renamed to src/Services/SagaManager/SagaManager/IntegrationEvents/Events/ConfirmGracePeriodCommandMsg.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
// Integration Events notes:
66
// An Event is “something that has happened in the past”, therefore its name has to be
77
// An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems.
8-
public class ConfirmGracePeriodIntegrationEvent : IntegrationEvent
8+
public class ConfirmGracePeriodCommandMsg : IntegrationEvent
99
{
1010
public int OrderId { get;}
1111

12-
public ConfirmGracePeriodIntegrationEvent(int orderId) => OrderId = orderId;
12+
public ConfirmGracePeriodCommandMsg(int orderId) => OrderId = orderId;
1313
}
1414
}

src/Services/SagaManager/SagaManager/IntegrationEvents/IConfirmGracePeriodEvent.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace SagaManager.IntegrationEvents
2+
{
3+
using System.Threading.Tasks;
4+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
5+
6+
public interface ISagaManagingIntegrationEventService
7+
{
8+
Task PublishThroughEventBusAsync(IntegrationEvent evt);
9+
}
10+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace SagaManager.IntegrationEvents
2+
{
3+
using System.Data.Common;
4+
using System.Threading.Tasks;
5+
using Microsoft.EntityFrameworkCore;
6+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
7+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
8+
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services;
9+
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
10+
using System;
11+
12+
public class SagaManagingIntegrationEventService : ISagaManagingIntegrationEventService
13+
{
14+
private readonly Func<DbConnection, IIntegrationEventLogService> _integrationEventLogServiceFactory;
15+
private readonly IEventBus _eventBus;
16+
private readonly OrderingContext _orderingContext;
17+
private readonly IIntegrationEventLogService _eventLogService;
18+
19+
public SagaManagingIntegrationEventService(IEventBus eventBus, OrderingContext orderingContext,
20+
Func<DbConnection, IIntegrationEventLogService> integrationEventLogServiceFactory)
21+
{
22+
_orderingContext = orderingContext ?? throw new ArgumentNullException(nameof(orderingContext));
23+
_integrationEventLogServiceFactory = integrationEventLogServiceFactory ?? throw new ArgumentNullException(nameof(integrationEventLogServiceFactory));
24+
_eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
25+
_eventLogService = _integrationEventLogServiceFactory(_orderingContext.Database.GetDbConnection());
26+
}
27+
28+
public async Task PublishThroughEventBusAsync(IntegrationEvent evt)
29+
{
30+
_eventBus.Publish(evt);
31+
32+
await _eventLogService.MarkEventAsPublishedAsync(evt);
33+
}
34+
}
35+
}

src/Services/SagaManager/SagaManager/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static IServiceProvider ConfigureServices(IServiceCollection services)
5555
.AddOptions()
5656
.Configure<SagaManagerSettings>(Configuration)
5757
.AddSingleton<ISagaManagerService, SagaManagerService>()
58-
.AddSingleton<IConfirmGracePeriodEvent, ConfirmGracePeriodEvent>()
58+
.AddSingleton<ISagaManagingIntegrationEventService, SagaManagingIntegrationEventService>()
5959
.AddSingleton<IEventBus, EventBusRabbitMQ>()
6060
.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>()
6161
.AddSingleton<IRabbitMQPersistentConnection>(sp =>

src/Services/SagaManager/SagaManager/SagaManager.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
<ItemGroup>
2222
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusRabbitMQ\EventBusRabbitMQ.csproj" />
2323
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBus\EventBus.csproj" />
24+
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\IntegrationEventLogEF\IntegrationEventLogEF.csproj" />
25+
<ProjectReference Include="..\..\Ordering\Ordering.Infrastructure\Ordering.Infrastructure.csproj" />
2426
</ItemGroup>
2527

2628
<ItemGroup>

src/Services/SagaManager/SagaManager/Services/SagaManagerService.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Threading.Tasks;
23
using Microsoft.Extensions.Logging;
34

45
namespace SagaManager.Services
@@ -13,15 +14,15 @@ namespace SagaManager.Services
1314
public class SagaManagerService : ISagaManagerService
1415
{
1516
private readonly SagaManagerSettings _settings;
16-
private readonly IConfirmGracePeriodEvent _confirmGracePeriodEvent;
17+
private readonly ISagaManagingIntegrationEventService _sagaManagingIntegrationEventService;
1718
private readonly ILogger<SagaManagerService> _logger;
1819

1920
public SagaManagerService(IOptions<SagaManagerSettings> settings,
20-
IConfirmGracePeriodEvent confirmGracePeriodEvent,
21+
ISagaManagingIntegrationEventService sagaManagingIntegrationEventService,
2122
ILogger<SagaManagerService> logger)
2223
{
2324
_settings = settings.Value;
24-
_confirmGracePeriodEvent = confirmGracePeriodEvent;
25+
_sagaManagingIntegrationEventService = sagaManagingIntegrationEventService;
2526
_logger = logger;
2627
}
2728

@@ -59,12 +60,12 @@ WHERE DATEDIFF(hour, [OrderDate], GETDATE()) >= @GracePeriod
5960
return orderIds;
6061
}
6162

62-
private void Publish(int orderId)
63+
private async Task Publish(int orderId)
6364
{
64-
var confirmGracePeriodEvent = new ConfirmGracePeriodIntegrationEvent(orderId);
65+
var confirmGracePeriodEvent = new ConfirmGracePeriodCommandMsg(orderId);
6566

6667
// Publish through the Event Bus
67-
_confirmGracePeriodEvent.PublishThroughEventBus(confirmGracePeriodEvent);
68+
await _sagaManagingIntegrationEventService.PublishThroughEventBusAsync(confirmGracePeriodEvent);
6869
}
6970
}
7071
}

0 commit comments

Comments
 (0)