Skip to content

Commit 840f3c7

Browse files
Move UseTransport to extension type similar to how persistence, serializer works (#7451)
* Move UseTransport to extension type similar to how persistence, serializer etc. works * Skip extension method It will still fail when an extension method doesn't end with a period or is empty * Simplify * Add more documentation --------- Co-authored-by: Daniel Marbach <[email protected]>
1 parent fad98f8 commit 840f3c7

File tree

4 files changed

+49
-43
lines changed

4 files changed

+49
-43
lines changed

src/NServiceBus.Core.Tests/ApprovalFiles/APIApprovals.ApproveNServiceBus.approved.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,6 @@ namespace NServiceBus
274274
public NServiceBus.ConventionsBuilder Conventions() { }
275275
public void RegisterComponents(System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> registration) { }
276276
public void SendOnly() { }
277-
public NServiceBus.RoutingSettings<TTransport> UseTransport<TTransport>(TTransport transportDefinition)
278-
where TTransport : NServiceBus.Transport.TransportDefinition { }
279277
}
280278
public static class EndpointConfigurationExtensions
281279
{
@@ -981,6 +979,18 @@ namespace NServiceBus
981979
public ToSagaExpression(NServiceBus.IConfigureHowToFindSagaWithMessage sagaMessageFindingConfiguration, System.Linq.Expressions.Expression<System.Func<TMessage, object?>> messageProperty) { }
982980
public void ToSaga(System.Linq.Expressions.Expression<System.Func<TSagaData, object?>> sagaEntityProperty) { }
983981
}
982+
public static class TransportConfig
983+
{
984+
public static NServiceBus.RoutingSettings<TTransport> UseTransport<TTransport>(this NServiceBus.EndpointConfiguration endpointConfiguration, TTransport transportDefinition)
985+
where TTransport : notnull, NServiceBus.Transport.TransportDefinition { }
986+
public sealed class <G>$AA4D0E78385CDABA9697E12267F940F2
987+
{
988+
[System.Runtime.CompilerServices.ExtensionMarker("<M>$B2E337D1C9DAD3813FD51F2C3BF89066")]
989+
public NServiceBus.RoutingSettings<TTransport> UseTransport<TTransport>(TTransport transportDefinition)
990+
where TTransport : NServiceBus.Transport.TransportDefinition { }
991+
public static class <M>$B2E337D1C9DAD3813FD51F2C3BF89066 { }
992+
}
993+
}
984994
public class TransportExtensions<T>
985995
where T : NServiceBus.Transport.TransportDefinition
986996
{

src/NServiceBus.Core.Tests/DocumentationTests.cs

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -70,38 +70,11 @@ protected override void VisitElement(Element element)
7070

7171
void AddIfEmpty(Element element)
7272
{
73-
if (element is TypeParamRef)
74-
{
75-
return;
76-
}
77-
if (element is C)
78-
{
79-
return;
80-
}
81-
if (element is SeeAlso)
82-
{
83-
return;
84-
}
85-
if (element is UnknownElement)
86-
{
87-
return;
88-
}
89-
if (element is Code)
90-
{
91-
return;
92-
}
93-
if (element is See)
94-
{
95-
return;
96-
}
97-
if (element is Text)
98-
{
99-
return;
100-
}
101-
if (element is ParamRef)
73+
if (SkipElementTypes(element))
10274
{
10375
return;
10476
}
77+
10578
var text = element.ToText();
10679
if (text == null)
10780
{
@@ -135,6 +108,13 @@ void AddIfEmpty(Element element)
135108
BadMembers.Add(currentMember);
136109
}
137110

111+
static bool SkipElementTypes(Element element) =>
112+
element switch
113+
{
114+
TypeParamRef or C or SeeAlso or UnknownElement or Code or See or Text or ParamRef or ExtensionMethod => true,
115+
_ => false,
116+
};
117+
138118
bool IsInheritDoc(Element element)
139119
{
140120
var lineInfoField = GetLineInfoField(element.GetType());

src/NServiceBus.Core/EndpointConfiguration.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ namespace NServiceBus;
99
using Microsoft.Extensions.DependencyInjection;
1010
using Pipeline;
1111
using Settings;
12-
using Transport;
1312

1413
/// <summary>
1514
/// Configuration used to create an endpoint instance.
1615
/// </summary>
17-
public partial class EndpointConfiguration : ExposeSettings
16+
public class EndpointConfiguration : ExposeSettings
1817
{
1918
/// <summary>
2019
/// Initializes the endpoint configuration builder.
@@ -98,16 +97,6 @@ public ConventionsBuilder Conventions()
9897
return ConventionsBuilder;
9998
}
10099

101-
/// <summary>
102-
/// Configures NServiceBus to use the given transport.
103-
/// </summary>
104-
public RoutingSettings<TTransport> UseTransport<TTransport>(TTransport transportDefinition)
105-
where TTransport : TransportDefinition
106-
{
107-
Settings.Get<TransportSeam.Settings>().TransportDefinition = transportDefinition;
108-
return new RoutingSettings<TTransport>(Settings);
109-
}
110-
111100
//This needs to be here since we have downstreams that use reflection to access this property
112101
internal void TypesToScanInternal(IEnumerable<Type> typesToScan)
113102
{
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#nullable enable
2+
3+
namespace NServiceBus;
4+
5+
using Configuration.AdvancedExtensibility;
6+
using Transport;
7+
8+
/// <summary>
9+
/// Enables users to select the transport by calling .UseTransport().
10+
/// </summary>
11+
public static class TransportConfig
12+
{
13+
extension(EndpointConfiguration endpointConfiguration)
14+
{
15+
/// <summary>
16+
/// Configures NServiceBus to use the given transport.
17+
/// </summary>
18+
/// <typeparam name="TTransport">The transport definition eg <see cref="LearningTransport" />, AzureServiceBusTransport etc.</typeparam>
19+
public RoutingSettings<TTransport> UseTransport<TTransport>(TTransport transportDefinition)
20+
where TTransport : TransportDefinition
21+
{
22+
var settings = endpointConfiguration.GetSettings();
23+
settings.Get<TransportSeam.Settings>().TransportDefinition = transportDefinition;
24+
return new RoutingSettings<TTransport>(settings);
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)