我们使用与IExtensionConfigProvider的参数绑定在Azure函数(netstandard20上的v2)中使用依赖注入.将Microsoft.NET.Sdk.Functions从1.0.13升级到1.0.19(强制将Microsoft.Azure.Webjobs.Host升级到v3)之后,这不再起作用了.我无法在IExtensionConfigProvider.Initialize函数中找到断点.相同版本的Functions SDK适用于具有目标框架net462的示例项目,它使用Microsoft.Azure.WebJobs v2.
这是它在运行时给出的错误:
错误索引方法'Function1.Run'.Microsoft.Azure.WebJobs.Host:无法将参数'customThing'绑定到CustomType类型.确保绑定支持参数Type.
这是示例应用程序的代码:
public static class Function1
{
[FunctionName("ThisFunction")]
public static async Task Run(
[TimerTrigger("0 */1 * * * *")]TimerInfo timer,
[Inject(typeof(CustomType))] CustomType customThing,
ExecutionContext context)
{
Console.WriteLine(customThing.GetMessage());
}
}
public class CustomType
{
public string GetMessage() => "Hi";
}
[Binding]
[AttributeUsage(AttributeTargets.Parameter)]
public class InjectAttribute : Attribute
{
public Type Type { get; }
public InjectAttribute(Type type) => Type = type;
}
public class InjectConfiguration : IExtensionConfigProvider
{
private IServiceProvider _serviceProvider;
public void Initialize(ExtensionConfigContext context)
{
var …
Run Code Online (Sandbox Code Playgroud)