public async Task Handle(IHttpContext httpContext, Func <Task> next) { IHttpRequest httpRequest = httpContext.Request; var call = new RestCall(httpRequest.Method, httpRequest.RequestParameters.Length > 1); Func <IRestController <T>, IHttpRequest, Task <object> > handler; if (RestCallHandlers.TryGetValue(call, out handler)) { var value = await handler(_controller, httpRequest).ConfigureAwait(false); httpContext.Response = await _responseProvider.Provide(value); return; } await next().ConfigureAwait(false); }