public virtual async Task <HttpResponseMessage> Invoke(object handler) { var actionArguments = new object[_actionDescriptor .Action.MethodDescriptor.Parameters.Length]; if (actionArguments.Any()) { var requestBinderContext = new RequestBinderContext(actionArguments); foreach (var binder in _actionDescriptor.RequestBinders .ThatApplyTo(_requestBinders, requestBinderContext)) { var result = await binder.Bind(requestBinderContext); switch (result.Status) { case BindingStatus.Failure: return(SetStatus(ResponseState.BindingFailure, result.ErrorMessage)); case BindingStatus.NoReader: return(SetStatus(ResponseState.NoReader)); } } } var response = await _actionDescriptor.Action.Invoke(handler, actionArguments); if (response is HttpResponseMessage) { return(response.As <HttpResponseMessage>()); } if (!_actionDescriptor.Route.HasResponse) { return(SetStatus(ResponseState.NoResponse)); } var writer = _writers.ThatApply(response, _actionDescriptor).FirstOrDefault(); if (writer == null) { return(SetStatus(ResponseState.NoWriter)); } SetStatus(ResponseState.HasResponse); return(await writer.Write(response)); }
public Task Bind(RequestBinderContext context) { BindCalled = true; BindContext = context; return(BindFunc(context)); }
public bool AppliesTo(RequestBinderContext context) { AppliesToCalled = true; AppliesToContext = context; return(AppliesToFunc?.Invoke(context) ?? true); }
private static Task <BindResult> SetArguments(ActionMethod actionMethod, RequestBinderContext context, Action <object[], ParameterDescriptor> set) { actionMethod.MethodDescriptor.Parameters.ForEach(pi => set(context.ActionArguments, pi)); return(BindResult.Success().ToTaskResult()); }
private static Task SetArguments(RequestBinderContext context, Action <object[], ParameterDescriptor> set) { context.RequestContext.Action.Method.Parameters.ForEach(pi => set(context.ActionArguments, pi)); return(Task.CompletedTask); }
public static Task <object> Read(this IRequestReader reader, RequestBinderContext context) { return(reader.Read(new RequestReaderContext(context.Configuration, context.RequestContext))); }