上下文:在 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,从而让它知道它在整个过程中的“位置”?(对我来说似乎不干净。)