Skip to content

Commit c507d36

Browse files
authored
update to NSB 10 (#322)
* update to NSB 10 * .
1 parent e78646f commit c507d36

5 files changed

Lines changed: 24 additions & 11 deletions

File tree

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project>
33
<PropertyGroup>
4-
<Version>3.1.0</Version>
4+
<Version>4.0.0</Version>
55
<AssemblyVersion>1.0.0</AssemblyVersion>
66
<LangVersion>preview</LangVersion>
77
<PackageTags>NServiceBus, Handler Ordering</PackageTags>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<RootNamespace>NServiceBus.HandlerOrdering</RootNamespace>
66
</PropertyGroup>
77
<ItemGroup>
8-
<PackageReference Include="NServiceBus" Version="9.2.7" />
8+
<PackageReference Include="NServiceBus" Version="10.0.0" />
99
<PackageReference Include="ProjectDefaults" Version="1.0.170" PrivateAssets="all" />
1010
</ItemGroup>
1111
</Project>

src/HandlerOrdering/OrderHandlers.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
class OrderHandlers :
22
INeedInitialization
33
{
4+
static readonly Lazy<MethodInfo> addHandlerMethod = new(() =>
5+
{
6+
var extensionsType = typeof(EndpointConfiguration).Assembly.GetType("NServiceBus.MessageHandlerRegistrationExtensions");
7+
return extensionsType?.GetMethod("AddHandler", BindingFlags.Static | BindingFlags.Public)
8+
?? throw new("Could not find 'AddHandler' method on MessageHandlerRegistrationExtensions. Raise an issue here https://github.com/NServiceBusCommunity/NServiceBus.Community.HandlerOrdering/issues/new");
9+
});
10+
411
public void Customize(EndpointConfiguration configuration)
512
{
613
if (configuration.GetApplyInterfaceHandlerOrdering())
@@ -13,19 +20,21 @@ static void ApplyInterfaceHandlerOrdering(EndpointConfiguration configuration)
1320
{
1421
var handlerDependencies = GetHandlerDependencies(configuration);
1522
var sorted = new TypeSorter(handlerDependencies).Sorted;
16-
configuration.ExecuteTheseHandlersFirst(sorted);
23+
24+
foreach (var handlerType in sorted)
25+
{
26+
var genericMethod = addHandlerMethod.Value.MakeGenericMethod(handlerType);
27+
genericMethod.Invoke(null, [configuration]);
28+
}
1729
}
1830

1931
static Dictionary<Type, List<Type>> GetHandlerDependencies(EndpointConfiguration configuration)
2032
{
21-
var field = typeof(EndpointConfiguration)
22-
.GetField("scannedTypes", BindingFlags.Instance | BindingFlags.NonPublic);
23-
if (field == null)
33+
var settings = configuration.GetSettings();
34+
if (!settings.TryGet("TypesToScan", out List<Type> types))
2435
{
25-
throw new($"Could not extract 'scannedTypes' field from {nameof(EndpointConfiguration)}. Raise an issue here https://github.com/NServiceBusExtensions/NServiceBus.HandlerOrdering/issues/new");
36+
throw new("Could not extract 'TypesToScan' from settings. Raise an issue here https://github.com/NServiceBusCommunity/NServiceBus.Community.HandlerOrdering/issues/new");
2637
}
27-
28-
var types = (List<Type>) field.GetValue(configuration)!;
2938
return GetHandlerDependencies(types);
3039
}
3140

src/HandlerOrdering/TypeSorter.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public TypeSorter(Dictionary<Type, List<Type>> dependencies)
1414
stack = new();
1515
Visit(item);
1616
}
17+
1718
Sorted = new(sorted);
1819
}
1920

@@ -36,8 +37,10 @@ void Visit(Type item)
3637

3738
throw new(stringBuilder.ToString());
3839
}
40+
3941
return;
4042
}
43+
4144
visited.Add(item);
4245
if (dependencies.TryGetValue(item, out var values))
4346
{
@@ -46,6 +49,7 @@ void Visit(Type item)
4649
Visit(dependency);
4750
}
4851
}
52+
4953
sorted.Add(item);
5054
}
5155
}

src/Sample/Sample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<LangVersion>7.1</LangVersion>
66
</PropertyGroup>
77
<ItemGroup>
8-
<PackageReference Include="NServiceBus" Version="9.2.7" />
8+
<PackageReference Include="NServiceBus" Version="10.0.0" />
99
<ProjectReference Include="..\HandlerOrdering\NServiceBus.Community.HandlerOrdering.csproj" />
1010
</ItemGroup>
1111
</Project>

0 commit comments

Comments
 (0)