feat(dispatcher): add registration-time pipeline behavior ordering via AddBehavior<T>(order:)
All checks were successful
default / dotnet-default-workflow (push) Successful in 1m58s

Pipeline behavior ordering previously depended on discovery/registration
order. Add an AddBehavior<T>(order:) API that captures the order at
registration time; the BehaviorTypeIndex now orders matching behaviors by
that explicit order (lower runs first), falling back to registration order
for ties. Removed the runtime Order property approach.
This commit is contained in:
Louis Seubert 2026-07-12 19:30:59 +02:00
commit ae2c2679f2
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD
7 changed files with 143 additions and 17 deletions

View file

@ -87,6 +87,26 @@ internal sealed class ScalarBehaviourTests
await Assert.That(tracker.Executed).IsTrue();
}
[Test]
public async Task I_can_order_behaviours_explicitly_by_order_property()
{
var sc = new ServiceCollection();
sc.AddSingleton<ScalarTestTracker>();
sc.AddRequestDispatcher(builder => builder
.Add(typeof(ScalarTestHandler))
.AddBehavior<OrderedScalarBehaviorA>(2)
.AddBehavior<OrderedScalarBehaviorB>(1));
var provider = sc.BuildServiceProvider();
var dispatcher = provider.GetRequiredService<IRequestDispatcher>();
var tracker = provider.GetRequiredService<ScalarTestTracker>();
var request = new ScalarTestRequest { Value = "Hello" };
await dispatcher.DispatchAsync(request);
// Registered A (order 2) then B (order 1) via AddBehavior; explicit order overrides discovery order.
await Assert.That(tracker.Log).IsEquivalentTo(["OrderedB", "OrderedA"]);
}
[Test]
public async Task I_can_maintain_the_ordering_between_open_and_closed_behaviours()
{