feat(dispatcher): add registration-time pipeline behavior ordering via AddBehavior<T>(order:)
All checks were successful
default / dotnet-default-workflow (push) Successful in 1m58s
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:
parent
595ba01ea6
commit
ae2c2679f2
7 changed files with 143 additions and 17 deletions
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue