使用依赖项注入时未注册持久的 Azure 函数绑定类型 [英] Durable Azure function binding types not registered when using dependency injection

查看:31
本文介绍了使用依赖项注入时未注册持久的 Azure 函数绑定类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个基于 Visual Studio 的标准持久函数添加新函数"到项目中.这开箱即用.

I created a standard durable function based from visual studio "Add new function" to project. This works fine out of the box.

然后我按照这里的步骤操作:https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection 添加依赖注入.添加 Microsoft.Extensions.http.

Then I followed the steps here: https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection to add dependency injection. Adding Microsoft.Extensions.http.

这破坏了功能,我得到错误:

This breaks the function and I get error:

[03-Mar-20 14:58:18] The 'test' function is in error: The binding type(s) 'orchestrationTrigger' are not registered. Please ensure the type is correct and the binding extension is installed.
[03-Mar-20 14:58:18] The 'test_Hello' function is in error: The binding type(s) 'activityTrigger' are not registered. Please ensure the type is correct and the binding extension is installed.
[03-Mar-20 14:58:18] The 'test_HttpStart' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'test_HttpStart'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'starter' to type IDurableOrchestrationClient. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

在这种状态下,startup.cs 不会运行,这在我之前创建的函数中从未发生过,但我可以通过添加包含以下内容的 extensions.json 来解决此问题:

In this state startup.cs does not run, which has never happened before in previous functions I have created, but I can fix this by adding extensions.json with the following content:

{
  "extensions": [
    {
      "name": "Startup",
      "typeName": "FunctionApp1.Startup, FunctionApp1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
    }
  ]
}

这使 startup.cs 中的 Configure 方法运行,但我仍然遇到相同的错误.

This makes Configure method in startup.cs run, but I still get the same errors.

startup.cs

public override void Configure(IFunctionsHostBuilder builder)
{
    builder.Services.AddHttpClient();
}

Function2.cs

Function2.cs

公共类Function2{[功能名称(测试")]公共异步任务> RunOrchestrator([OrchestrationTrigger] IDurableOrchestrationContext 上下文){var 输出 = new List();

public class Function2 { [FunctionName("test")] public async Task> RunOrchestrator( [OrchestrationTrigger] IDurableOrchestrationContext context) { var outputs = new List();

        // Replace "hello" with the name of your Durable Activity Function.
        outputs.Add(await context.CallActivityAsync<string>("test_Hello", "Tokyo"));
        outputs.Add(await context.CallActivityAsync<string>("test_Hello", "Seattle"));
        outputs.Add(await context.CallActivityAsync<string>("test_Hello", "London"));

        // returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
        return outputs;
    }

    [FunctionName("test_Hello")]
    public string SayHello([ActivityTrigger] string name, ILogger log)
    {
        log.LogInformation($"Saying hello to {name}.");
        return $"Hello {name}!";
    }

    [FunctionName("test_HttpStart")]
    public async Task<HttpResponseMessage> HttpStart(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")]HttpRequestMessage req,
        [DurableClient]IDurableOrchestrationClient starter,
        ILogger log)
    {
        // Function input comes from the request content.
        string instanceId = await starter.StartNewAsync("test", null);

        log.LogInformation($"Started orchestration with ID = '{instanceId}'.");

        return starter.CreateCheckStatusResponse(req, instanceId);
    }
}

我使用的是 .net core 3.1Microsoft.Azure.Functions.Extensions 1.0.0

I am using .net core 3.1 Microsoft.Azure.Functions.Extensions 1.0.0

Microsoft.Azure.WebJobs.Extensions.DurableTask 2.1.1

Microsoft.Azure.WebJobs.Extensions.DurableTask 2.1.1

Microsoft.Extensions.Http 3.1.2

Microsoft.Extensions.Http 3.1.2

Microsoft.NET.sdk.Functions 3.0.4

Microsoft.NET.sdk.Functions 3.0.4

推荐答案

暂时尝试将 Microsoft.NET.sdk.Functions 3.0.4 降级到以前的版本.团队进行了一些性能改进,但我看到有人提出了同样的问题(DI 问题)

Just for now, try downgrading the Microsoft.NET.sdk.Functions 3.0.4 to a previuos version. The team made some performance improvements, but I've seen people raising the same issue (DI problems)

这篇关于使用依赖项注入时未注册持久的 Azure 函数绑定类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆