Skip to content

Commit

Permalink
Set the RequestFilterBehavior before the ValidationBehavior (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-peshkov committed Jul 3, 2024
1 parent f27dfc4 commit 88623a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Cross.CQRS/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public static CqrsRegistrationSyntax AddCQRS(this IServiceCollection services, p

// Registration order is important, it works like ASP.NET Core middleware
// Behaviors registered earlier will be executed earlier
behaviorCollection.AddBehavior(typeof(EventQueueProcessBehavior<,>), order: int.MinValue);
behaviorCollection.AddBehavior(typeof(ValidationBehavior<,>), order: 1);
behaviorCollection.AddBehavior(typeof(RequestFilterBehavior<,>), order: 2);
behaviorCollection.AddBehavior(typeof(EventQueueProcessBehavior<,>), order: 0);
behaviorCollection.AddBehavior(typeof(RequestFilterBehavior<,>), order: 1);
behaviorCollection.AddBehavior(typeof(ValidationBehavior<,>), order: 2);
behaviorCollection.AddBehavior(typeof(ResultFilterBehavior<,>), order: 3);

return new CqrsRegistrationSyntax(services, assemblies, behaviorCollection);
Expand Down
11 changes: 11 additions & 0 deletions SampleWebApp/Modules/Some/Handlers/SomeRequestFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace SampleWebApp.Modules.Some.Handlers;

public class SomeRequestFilter : RequestFilter<SomeQuery, IEnumerable<string>>
{
public override Task<SomeQuery> ApplyFilterAsync(SomeQuery request, CancellationToken cancellationToken)
{
// do some filter actions

return Task.FromResult(request);
}
}

0 comments on commit 88623a8

Please sign in to comment.