Skip to content

Commit 6d574ae

Browse files
Introduce subscribe overloads that allow mapping to implementation type using the default convention (#1175)
Co-authored-by: danielmarbach <danielmarbach@users.noreply.github.com>
1 parent 86daed6 commit 6d574ae

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Tests/ApprovalFiles/APIApprovals.Approve.approved.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ namespace NServiceBus.Transport.AzureServiceBus
244244
public void PublishTo(System.Type eventType, string topicName) { }
245245
public void PublishTo<TEventType>(string topicName) { }
246246
public void SubscribeTo(System.Type eventType, string topicName) { }
247+
public void SubscribeTo(System.Type eventType, System.Type eventTypeImplementation) { }
247248
public void SubscribeTo<TEventType>(string topicName) { }
249+
public void SubscribeTo<TEventType, TEventTypeImplementation>()
250+
where TEventTypeImplementation : TEventType { }
248251
}
249252
[System.Text.Json.Serialization.JsonDerivedType(typeof(NServiceBus.Transport.AzureServiceBus.MigrationTopologyOptions), "migration-topology-options")]
250253
[System.Text.Json.Serialization.JsonDerivedType(typeof(NServiceBus.Transport.AzureServiceBus.TopologyOptions), "topology-options")]

src/Transport/EventRouting/TopicPerEventTopology.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,29 @@ public void PublishTo(Type eventType, string topicName)
3636
Options.PublishedEventToTopicsMap[eventType.FullName] = topicName;
3737
}
3838

39+
/// <summary>
40+
/// Instructs the topology to use provided topic to subscribe for events of a given type applying the default convention
41+
/// of subscribing to the event under a topic name that is the full name of the event type.
42+
/// </summary>
43+
/// <typeparam name="TEventType">Type of the event.</typeparam>
44+
/// <typeparam name="TEventTypeImplementation">Type of the event implementation.</typeparam>
45+
/// <exception cref="ArgumentException">The topic name is not set.</exception>
46+
public void SubscribeTo<TEventType, TEventTypeImplementation>() where TEventTypeImplementation : TEventType =>
47+
SubscribeTo(typeof(TEventType), typeof(TEventTypeImplementation));
48+
49+
/// <summary>
50+
/// Instructs the topology to use provided topic to subscribe for events of a given type applying the default convention
51+
/// of subscribing to the event under a topic name that is the full name of the event type.
52+
/// </summary>
53+
/// <param name="eventType">Name of the topic to subscribe to.</param>
54+
/// <param name="eventTypeImplementation">Type of the event implementation.</param>
55+
/// <exception cref="ArgumentException">The topic name is not set.</exception>
56+
public void SubscribeTo(Type eventType, Type eventTypeImplementation)
57+
{
58+
ArgumentException.ThrowIfNullOrWhiteSpace(eventTypeImplementation.FullName);
59+
SubscribeTo(eventType, eventTypeImplementation.FullName);
60+
}
61+
3962
/// <summary>
4063
/// Instructs the topology to use provided topic to subscribe for events of a given type.
4164
/// </summary>

0 commit comments

Comments
 (0)