Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the NamingPolicy for the event of event storage #13

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Configurations/BaseEventOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using EventBus.RabbitMQ.Models;
using EventStorage.Models;

namespace EventBus.RabbitMQ.Configurations;

Expand Down
27 changes: 4 additions & 23 deletions src/Configurations/RabbitMqHostSettings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Reflection;
using System.Security.Authentication;
using System.Text.Json;
using EventBus.RabbitMQ.Models;
using EventStorage.Models;

namespace EventBus.RabbitMQ.Configurations;

Expand Down Expand Up @@ -165,32 +165,13 @@ internal string GetCorrectEventNameBasedOnNamingPolicy(string eventName)
/// <summary>
/// Gets JsonNamingPolicy to use on naming police for serializing and deserializing the name of Event
/// </summary>
internal JsonNamingPolicy GetEventNamingPolicy()
private JsonNamingPolicy GetEventNamingPolicy()
{
if (_isEventNamingPolicyInitialized)
return _eventNamingPolicy;

switch (EventNamingPolicy)
{
case NamingPolicyType.CamelCase:
_eventNamingPolicy = JsonNamingPolicy.CamelCase;
break;
case NamingPolicyType.SnakeCaseLower:
_eventNamingPolicy = JsonNamingPolicy.SnakeCaseLower;
break;
case NamingPolicyType.SnakeCaseUpper:
_eventNamingPolicy = JsonNamingPolicy.SnakeCaseUpper;
break;
case NamingPolicyType.KebabCaseLower:
_eventNamingPolicy = JsonNamingPolicy.KebabCaseLower;
break;
case NamingPolicyType.KebabCaseUpper:
_eventNamingPolicy = JsonNamingPolicy.KebabCaseUpper;
break;
default:
_eventNamingPolicy = null;
break;
}
var eventNamingPolicyType = EventNamingPolicy ?? NamingPolicyType.PascalCase;
_eventNamingPolicy = NamingPolicyTypeNames.GetEventNamingPolicy(eventNamingPolicyType.ToString());

_isEventNamingPolicyInitialized = true;

Expand Down
2 changes: 1 addition & 1 deletion src/Configurations/RabbitMqOptionsConstant.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Security.Authentication;
using EventBus.RabbitMQ.Models;
using EventStorage.Models;

namespace EventBus.RabbitMQ.Configurations;

Expand Down
2 changes: 1 addition & 1 deletion src/EventBus.RabbitMQ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AlifCapital.EventStorage" Version="9.0.4" />
<PackageReference Include="AlifCapital.EventStorage" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.0" />
Expand Down
11 changes: 0 additions & 11 deletions src/Models/NamingPolicyType.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Subscribers/Consumers/EventConsumerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private async Task Consumer_Received(object sender, BasicDeliverEventArgs eventA
$"The RabbitMQ is configured to use the Inbox for received events, but the Inbox functionality of the EventStorage is not enabled. So, the {info.eventHandlerType.Name} event subscriber of an event will be executed immediately for the event id: {eventId};");

_ = eventReceiverManager.Received(eventId, info.eventType.Name, eventArgs.RoutingKey,
EventProviderType.MessageBroker, payload: eventPayload, headers: headersAsJson);
EventProviderType.MessageBroker, payload: eventPayload, headers: headersAsJson, namingPolicyType: info.eventSettings.PropertyNamingPolicy ?? NamingPolicyType.PascalCase);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using EventBus.RabbitMQ.Configurations;
using EventBus.RabbitMQ.Models;
using EventBus.RabbitMQ.Subscribers.Options;
using EventStorage.Models;
using FluentAssertions;

namespace EventBus.RabbitMQ.Tests.UnitTests.Subscribers;
Expand Down
Loading