Skip to content

Commit

Permalink
VCST-430: Simplify event handlers registration (#19)
Browse files Browse the repository at this point in the history
* Simplify event handlers registration

* Fix code smell

* Update dependencies
  • Loading branch information
artem-dudarev authored Mar 15, 2024
1 parent d18bd86 commit b818cc4
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="VirtoCommerce.Platform.Core" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.Platform.Core" Version="3.814.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ public class DefaultEventBusSubscriptionsManager : IEventBusSubscriptionsManager
{
private readonly ISubscriptionService _subscriptionService;
private readonly IProviderConnectionLogService _providerConnectionLogService;
private readonly IHandlerRegistrar _eventHandlerRegistrar;
private readonly IEventHandlerRegistrar _eventHandlerRegistrar;
private readonly RegisteredEventService _registeredEventService;
private readonly IEventBusSubscriptionsService _subscriptionsService;
private readonly IEventBusProviderConnectionsService _providerConnections;

public DefaultEventBusSubscriptionsManager(IHandlerRegistrar eventHandlerRegistrar,
public DefaultEventBusSubscriptionsManager(
IEventHandlerRegistrar eventHandlerRegistrar,
RegisteredEventService registeredEventService,
ISubscriptionService subscriptionService,
IProviderConnectionLogService providerConnectionLogService,
Expand Down Expand Up @@ -73,12 +74,7 @@ private async Task<bool> CheckConnection(string connectionName)

public virtual void RegisterEvents()
{
var allEvents = _registeredEventService.GetAllEvents();

foreach (var @event in allEvents)
{
InvokeHandler(@event.Type, _eventHandlerRegistrar);
}
_eventHandlerRegistrar.RegisterEventHandler<DomainEvent>(HandleEvent);
}


Expand Down Expand Up @@ -141,6 +137,7 @@ protected virtual async Task SendEvent(DomainEvent domainEvent, string eventId,
}
}

[Obsolete("Register event handler for DomainEvent", DiagnosticId = "VC0008", UrlFormat = "https://docs.virtocommerce.org/products/products-virto3-versions")]
protected virtual void InvokeHandler(Type eventType, IHandlerRegistrar registrar)
{
var registerExecutorMethod = registrar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Azure.Messaging.EventGrid" Version="4.21.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="Scriban" Version="5.9.0" />
<PackageReference Include="VirtoCommerce.Platform.Data" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.Platform.Data" Version="3.814.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VirtoCommerce.EventBusModule.Core\VirtoCommerce.EventBusModule.Core.csproj" />
Expand Down
4 changes: 3 additions & 1 deletion src/VirtoCommerce.EventBusModule.Web/module.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
<id>VirtoCommerce.EventBus</id>
<version>3.801.0</version>
<version-tag />
<platformVersion>3.800.0</platformVersion>

<platformVersion>3.814.0</platformVersion>
<dependencies />

<title>Event Bus module</title>
<description>The module enables you to be notified of new messages or changes via a Message Queue of your choice</description>
<authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async Task SaveSubscriptionAsync_TrySaveUnknownProvider_ThrowException()
Assert.Equal("The provider connection Unknown_Provider is not registered", ex.Message);
}

private static DefaultEventBusSubscriptionsManager GetEventBusSubscriptionsManager(IHandlerRegistrar handlerRegistrar, ISubscriptionService subscriptionService)
private static DefaultEventBusSubscriptionsManager GetEventBusSubscriptionsManager(IEventHandlerRegistrar eventHandlerRegistrar, ISubscriptionService subscriptionService)
{
var registeredEventServiceMock = new Mock<RegisteredEventService>(Mock.Of<IPlatformMemoryCache>());
var eventTypes = new List<PlatformEventInfo>
Expand All @@ -103,7 +103,7 @@ private static DefaultEventBusSubscriptionsManager GetEventBusSubscriptionsManag
eventBusProviderServiceMock.Setup(x => x.GetProviderConnectionAsync(It.Is<string>(x => x == "FakeProvider"))).ReturnsAsync(new ProviderConnection());
eventBusProviderServiceMock.Setup(x => x.GetConnectedProviderAsync(It.IsAny<string>())).ReturnsAsync(new FakeProvider());

return new DefaultEventBusSubscriptionsManager(handlerRegistrar,
return new DefaultEventBusSubscriptionsManager(eventHandlerRegistrar,
registeredEventServiceMock.Object,
subscriptionService,
Mock.Of<IProviderConnectionLogService>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<NoWarn>1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down

0 comments on commit b818cc4

Please sign in to comment.