Reputation: 25
Is there any way to run PreRequestFilters that are async? I can see that there's been a number of async request filters added, but no async version of PreRequestFilters.
It would be nice to have an async version of PreRequestFilters so that we can run async tasks before any Request Filter Attributes. The only way I can see of doing that at the moment is to use GlobalRequestFiltersAsync and make sure all Request Filter Attributes have a Priority >= 0.
Upvotes: 1
Views: 61
Reputation: 143284
There isn't an async version of PreRequestFilters
but you could use a custom RequestFilter Async Attribute with a -Priortity, e.g:
public class MyAsyncAttribute : RequestFilterAsyncAttribute
{
public MyAsyncAttribute()
{
// Priority -101, before any built-in request filter attributes
Priority = (int)RequestFilterPriority.Authenticate - 1;
}
public override Task ExecuteAsync(IRequest req, IResponse res, object requestDto)
{
//...
}
}
Upvotes: 1