如何解决什么是 IBinding 接口中带有两个参数的 BindAsync 方法
在 Azure WebJobs SDK 中,我们有 IBinding
接口。这个接口有一个方法 BindAsync
有两个参数,但我不明白第一个参数 object value
是什么以及这个重载方法什么时候被调用。
同样的问题与 ITriggerBinding
接口相关。
我试图在 SDK 代码源中找到答案。我知道 BindingSource
包含一个参数字典,其中键是参数名称,值是将提供给 BindAsync
方法的参数值,但我无法理解这些参数是什么以及它们在哪里从哪里来?
解决方法
更新
IBinding.BindAsync 方法 返回 Task<IValueProvider>
。
IBinding.BindAsync 的用法。
示例代码
public async Task BindAsync_String()
{
ParameterInfo parameterInfo = GetType().GetMethod("TestStringFunction").GetParameters()[0];
HttpTriggerAttributeBindingProvider.HttpTriggerBinding binding = new HttpTriggerAttributeBindingProvider.HttpTriggerBinding(new HttpTriggerAttribute(),parameterInfo,false);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post,"http://functions/myfunc?code=abc123");
request.Content = new StringContent("This is a test");
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/text");
FunctionBindingContext functionContext = new FunctionBindingContext(Guid.NewGuid(),CancellationToken.None,new TestTraceWriter(TraceLevel.Verbose));
ValueBindingContext context = new ValueBindingContext(functionContext,CancellationToken.None);
ITriggerData triggerData = await binding.BindAsync(request,context);
Assert.Equal(0,triggerData.BindingData.Count);
string result = (string)triggerData.ValueProvider.GetValue();
Assert.Equal("This is a test",result);
}
从示例代码 (HttpTrigger) 中,您会发现 request
、context
。它们是 BindAsync
中的两个参数。您将了解 BindAsync
的用法。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。