When using convention based routing I am able to use a DelegatingHandler to create a response wrapper by overriding the SendAsync method.
DelegatingHandler[] handler = new DelegatingHandler[] {
new ResponseWrapper()
};
var routeHandler = HttpClientFactory.CreatePipeline(new HttpControllerDispatcher(config), handler);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}",
defaults: null,
constraints: null,
handler: routeHandler
);
However, this approach does not work for methods that rely upon attribute routing. In my case convention based routing will not work for all scenarios and the routeHandler does not apply to the attribute based routes.
How can I apply a response wrapper to all attribute based route responses?