From 3b4ef5b2e11b7ad20c739355e1cc3cb408b21de9 Mon Sep 17 00:00:00 2001 From: Grover <135006+cdmdotnet@users.noreply.github.com> Date: Sat, 2 Nov 2024 18:42:49 +1300 Subject: [PATCH] Added better generation of Type for SagaEvents. --- .../Cqrs.Azure.ServiceBus/AzureServiceBus.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Framework/Azure/Cqrs.Azure.ServiceBus/AzureServiceBus.cs b/Framework/Azure/Cqrs.Azure.ServiceBus/AzureServiceBus.cs index 1c40fde6e..765a5fb19 100644 --- a/Framework/Azure/Cqrs.Azure.ServiceBus/AzureServiceBus.cs +++ b/Framework/Azure/Cqrs.Azure.ServiceBus/AzureServiceBus.cs @@ -1392,7 +1392,23 @@ BrokeredMessage CreateBrokeredMessage brokeredMessage.SessionId = messageWithOrderingKey.OrderKey; } brokeredMessage.AddUserProperty("CorrelationId", brokeredMessage.CorrelationId); - brokeredMessage.AddUserProperty("Type", messageType.FullName); + Type sagaType = typeof(Cqrs.Events.SagaEvent); + string typeName = null; + if (messageType.Assembly == sagaType.Assembly && messageType.Name == sagaType.Name && messageType.Namespace == sagaType.Namespace) + { + PropertyInfo eventProperty = messageType.GetProperty("Event"); + if (eventProperty != null) + { + object @event = eventProperty.GetValue(message); + if (@event != null) + { + typeName = $"{messageType.Namespace}.{messageType.Name}{{{@event.GetType().FullName}}}"; + } + } + } + if (string.IsNullOrWhiteSpace(typeName)) + typeName = messageType.FullName; + brokeredMessage.AddUserProperty("Type", typeName); brokeredMessage.AddUserProperty("Source", $"{Logger.LoggerSettings.ModuleName}/{Logger.LoggerSettings.Instance}/{Logger.LoggerSettings.Environment}/{Logger.LoggerSettings.EnvironmentInstance}"); brokeredMessage.AddUserProperty("Framework", // this compiler directive is intentionally .NET Core and not 4.8