From 086571cf3c9c4dc9688609cb920d41b3c2111be4 Mon Sep 17 00:00:00 2001 From: "Jeremy D. Miller" Date: Mon, 2 Dec 2024 07:46:53 -0600 Subject: [PATCH] Revert "Add support for routing messages based on attribute decoration" This reverts commit 5e5d77b53e995f6f4ca1ea6fadded05de9f07e06. --- .../CoreTests/Runtime/Green/Messages.cs | 4 +- src/Testing/CoreTests/Runtime/Red/Messages.cs | 11 +---- .../CoreTests/Runtime/SubscriptionTester.cs | 44 +------------------ .../Configuration/PublishingExpression.cs | 31 +------------ src/Wolverine/Runtime/Routing/RoutingScope.cs | 3 +- src/Wolverine/Runtime/Routing/Subscription.cs | 11 +---- .../Transports/Local/LocalTransport.cs | 2 +- 7 files changed, 8 insertions(+), 98 deletions(-) diff --git a/src/Testing/CoreTests/Runtime/Green/Messages.cs b/src/Testing/CoreTests/Runtime/Green/Messages.cs index 55f7de0d9..65343ead8 100644 --- a/src/Testing/CoreTests/Runtime/Green/Messages.cs +++ b/src/Testing/CoreTests/Runtime/Green/Messages.cs @@ -4,6 +4,4 @@ public class GreenMessage1; public class GreenMessage2; -public class GreenMessage3; - -public class GreenAttribute : Attribute; +public class GreenMessage3; \ No newline at end of file diff --git a/src/Testing/CoreTests/Runtime/Red/Messages.cs b/src/Testing/CoreTests/Runtime/Red/Messages.cs index aefde376a..d6be920cd 100644 --- a/src/Testing/CoreTests/Runtime/Red/Messages.cs +++ b/src/Testing/CoreTests/Runtime/Red/Messages.cs @@ -1,16 +1,7 @@ namespace CoreTests.Runtime.Red; -[Red] public class RedMessage1; -[Crimson] public class RedMessage2; -[Burgundy] -public class RedMessage3; - -public class RedAttribute : Attribute; - -public class CrimsonAttribute : RedAttribute; - -public class BurgundyAttribute : RedAttribute; +public class RedMessage3; \ No newline at end of file diff --git a/src/Testing/CoreTests/Runtime/SubscriptionTester.cs b/src/Testing/CoreTests/Runtime/SubscriptionTester.cs index ad2383241..114513fb9 100644 --- a/src/Testing/CoreTests/Runtime/SubscriptionTester.cs +++ b/src/Testing/CoreTests/Runtime/SubscriptionTester.cs @@ -45,17 +45,6 @@ public void description_of_type_name_rule() rule.ToString().ShouldBe("Message name is 'CoreTests.Runtime.RandomClass'"); } - [Fact] - public void description_of_attribute_rule() - { - var rule = new Subscription - { - BaseOrAttributeType = typeof(RandomClassAttribute), - Scope = RoutingScope.Attribute - }; - rule.ToString().ShouldBe("Message type is decorated with 'CoreTests.Runtime.RandomClassAttribute' or a derived type"); - } - [Fact] public void description_of_all_types() { @@ -96,20 +85,6 @@ public void positive_assembly_test() rule.Matches(typeof(DeleteUser)).ShouldBeTrue(); } - [Fact] - public void negative_attribute_test() - { - var rule = new Subscription - { - Scope = RoutingScope.Attribute, - BaseOrAttributeType = typeof(GreenAttribute) - }; - - rule.Matches(typeof(GreenMessage1)).ShouldBeFalse(); - rule.Matches(typeof(GreenMessage2)).ShouldBeFalse(); - rule.Matches(typeof(GreenMessage3)).ShouldBeFalse(); - } - [Fact] public void positive_namespace_test() { @@ -123,23 +98,6 @@ public void positive_namespace_test() rule.Matches(typeof(RedMessage2)).ShouldBeTrue(); rule.Matches(typeof(RedMessage3)).ShouldBeTrue(); } - - [Fact] - public void positive_attribute_test() - { - var rule = new Subscription - { - Scope = RoutingScope.Attribute, - BaseOrAttributeType = typeof(RedAttribute) - }; - - rule.Matches(typeof(RedMessage1)).ShouldBeTrue(); - rule.Matches(typeof(RedMessage2)).ShouldBeTrue(); - rule.Matches(typeof(RedMessage3)).ShouldBeTrue(); - } } -[RandomClass] -public class RandomClass; - -public class RandomClassAttribute : Attribute; \ No newline at end of file +public class RandomClass; \ No newline at end of file diff --git a/src/Wolverine/Configuration/PublishingExpression.cs b/src/Wolverine/Configuration/PublishingExpression.cs index 62a5598f3..84f971731 100644 --- a/src/Wolverine/Configuration/PublishingExpression.cs +++ b/src/Wolverine/Configuration/PublishingExpression.cs @@ -160,35 +160,6 @@ public PublishingExpression MessagesFromAssemblyContaining() return MessagesFromAssembly(typeof(T).Assembly); } - /// - /// Create a publishing rule for all messages decorated with the specified attribute type or a derived type - /// - /// - /// - public PublishingExpression MessagesDecoratedWith(Type attributeType) - { - AutoAddSubscriptions = true; - - _subscriptions.Add(new Subscription() - { - Scope = RoutingScope.Attribute, - BaseOrAttributeType = attributeType, - }); - - return this; - } - - /// - /// Create a publishing rule for all messages decorated with the attribute of type T or a derived type - /// - /// - /// - public PublishingExpression MessagesDecoratedWith() - where T : Attribute - { - return MessagesDecoratedWith(typeof(T)); - } - internal void AttachSubscriptions() { if (!_endpoints.Any()) @@ -211,6 +182,6 @@ internal void AddSubscriptionForAllMessages() /// public void MessagesImplementing() { - _subscriptions.Add(new Subscription { BaseOrAttributeType = typeof(T), Scope = RoutingScope.Implements }); + _subscriptions.Add(new Subscription { BaseType = typeof(T), Scope = RoutingScope.Implements }); } } \ No newline at end of file diff --git a/src/Wolverine/Runtime/Routing/RoutingScope.cs b/src/Wolverine/Runtime/Routing/RoutingScope.cs index bad655071..6edf130f2 100644 --- a/src/Wolverine/Runtime/Routing/RoutingScope.cs +++ b/src/Wolverine/Runtime/Routing/RoutingScope.cs @@ -7,6 +7,5 @@ public enum RoutingScope Type, TypeName, All, - Implements, - Attribute + Implements } \ No newline at end of file diff --git a/src/Wolverine/Runtime/Routing/Subscription.cs b/src/Wolverine/Runtime/Routing/Subscription.cs index 5002a1f19..a2e97e603 100644 --- a/src/Wolverine/Runtime/Routing/Subscription.cs +++ b/src/Wolverine/Runtime/Routing/Subscription.cs @@ -43,10 +43,7 @@ public string[] ContentTypes /// public string Match { get; init; } = string.Empty; - /// - /// A base type if matching on implementation or an attribute type if matching on decoration - /// - public Type? BaseOrAttributeType { get; init; } + public Type? BaseType { get; init; } /// /// Create a subscription for a specific message type @@ -83,8 +80,7 @@ public bool Matches(Type type) RoutingScope.Type => type.Name.EqualsIgnoreCase(Match) || type.FullName!.EqualsIgnoreCase(Match) || type.ToMessageTypeName().EqualsIgnoreCase(Match), RoutingScope.TypeName => type.ToMessageTypeName().EqualsIgnoreCase(Match), - RoutingScope.Implements => type.CanBeCastTo(BaseOrAttributeType!), - RoutingScope.Attribute => type.IsDefined(BaseOrAttributeType!, inherit: false), + RoutingScope.Implements => type.CanBeCastTo(BaseType!), _ => !type.CanBeCastTo() }; } @@ -144,9 +140,6 @@ public override string ToString() case RoutingScope.TypeName: return $"Message name is '{Match}'"; - - case RoutingScope.Attribute: - return $"Message type is decorated with '{BaseOrAttributeType?.FullName}' or a derived type"; } throw new ArgumentOutOfRangeException(); diff --git a/src/Wolverine/Transports/Local/LocalTransport.cs b/src/Wolverine/Transports/Local/LocalTransport.cs index e20560ce4..d09392a6b 100644 --- a/src/Wolverine/Transports/Local/LocalTransport.cs +++ b/src/Wolverine/Transports/Local/LocalTransport.cs @@ -36,7 +36,7 @@ public LocalTransport() : base(TransportConstants.Local, "Local (In Memory)") var agentQueue = _queues[TransportConstants.Agents]; agentQueue.TelemetryEnabled = false; agentQueue.Subscriptions.Add(new Subscription - { Scope = RoutingScope.Implements, BaseOrAttributeType = typeof(IAgentCommand) }); + { Scope = RoutingScope.Implements, BaseType = typeof(IAgentCommand) }); agentQueue.ExecutionOptions.MaxDegreeOfParallelism = 20; agentQueue.Role = EndpointRole.System; agentQueue.Mode = EndpointMode.BufferedInMemory;