问题标签 [modelbinder]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c# - 将数据从 ModelBinder 传递到自定义 InputFormatter
上下文:在 Asp.net Core 2.1 下的 WebAPI 中,我必须创建一个 POST 端点
,[server]/MyController/{Parameter1}/MoreRouteThing/. 我必须创建一个自定义IInputFormatter,因为默认格式化程序无法读取正文。
问题:为了能够格式化输入,IInputFormatter需要知道Parameter1.
我实现了一个IModelBinder处理这个模型的自定义,startup.cs使用自定义连接所有东西IModelBinderProvider(可能有点矫枉过正,但我想了解整个链条。)
在自定义IModelBinder中,我可以{Parameter1}使用类似的东西进行访问bindingContext.ActionContext.RouteData.Values["Parameter1"],但我不知道如何将其传递给IInputFormatter. 前者将 an 传递InputFormatterContext给后者,但该上下文对象中的任何内容似乎都不适合存储额外信息。
所以问题:如何将数据从 传递IModelBinder到IInputFormatter?我是否应该直接从 解析 url/路由IInputFormatter,从而让它知道它在整个过程中的“位置”?(对我来说似乎不干净。)