-
Notifications
You must be signed in to change notification settings - Fork 28
Description
I have a Controller with an async Action. I would like to register a ActionFiler (one that implements IAutofacActionFilter, My code is based on Web API 2, using the Autofac Web API intergration module) for that specific 'async' action in that controller. Following are the snippets I tried and it didn't work. But Synchronous actions do work as mentioned in the Autofac guideline documents.
Tried a few way of specifying the asyn action in the 'Register' configuration but nothing worked. Please refer to the snippets below for tried code.
builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration); builder.Register(componentContext => new RequestLatencyTrackerActionFilter()) .AsWebApiActionFilterFor<>((actionSelector) => Task.Run<IHttpActionResult>(() => actionSelector.GetMyActionAsync(default(string))))) .InstancePerApiRequest();
Or,
builder.Register(componentContext => new RequestLatencyTrackerActionFilter()) .AsWebApiActionFilterFor<>((actionSelector) => actionSelector.GetMyActionAsync(default(string)).Wait())) .InstancePerApiRequest();
A 'Non-async' action works,
builder.Register(componentContext => new RequestLatencyTrackerActionFilter()) .AsWebApiActionFilterFor<>((actionSelector) => actionSelector.GetMyNonAsyncAction(default(string)))) .InstancePerApiRequest();
Are registrations for async actions supported in the Autofac Web API integration modules?
Seems like this not tested and the behavior is undefined.
https://stackoverflow.com/questions/58139190/autofac-filters-for-specific-async-action-in-a-controller-not-working