protected MessageHandlerFunc GetMessageHandler(IBindingContext context, MethodInfo method) { var allowBinding = false; MiddlewareHelper.Go(bindingMiddleware, (handler, next) => handler.Handle(context, next), () => { allowBinding = true; }); if (!allowBinding) { return(null); } if (context.MessageClass == null) { throw new TopologyConfigurationException($"Method {method.Name} in controller {method.DeclaringType?.Name} does not resolve to a message class"); } var invalidBindings = context.Parameters.Where(p => !p.HasBinding).ToList(); // ReSharper disable once InvertIf if (invalidBindings.Count > 0) { var parameterNames = string.Join(", ", invalidBindings.Select(p => p.Info.Name)); throw new TopologyConfigurationException($"Method {method.Name} in controller {method.DeclaringType?.Name} has unknown parameters: {parameterNames}"); } var resultHandler = ((IBindingResultAccess)context.Result).GetHandler(); return(WrapMethod(method, context.Parameters.Select(p => ((IBindingParameterAccess)p).GetBinding()), resultHandler)); }
/// <inheritdoc /> public void ApplyBindingMiddleware(IControllerBindingContext context, Action lastHandler) { MiddlewareHelper.Go(bindingMiddleware, (handler, next) => handler.Handle(context, next), lastHandler); }