Надежные Azure типы привязки функций не зарегистрированы при использовании внедрения зависимостей - PullRequest
3 голосов
/ 03 марта 2020

Я создал стандартную долговременную функцию из визуальной студии «Добавить новую функцию» в проект. Это отлично работает из коробки.

Затем я следовал следующим шагам: https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection, чтобы добавить внедрение зависимости. Добавление Microsoft.Extensions.http.

Это нарушает функцию, и я получаю ошибку:

[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, чего никогда не было в предыдущих созданных мной функциях, но я могу исправить это путем добавления расширений. json со следующим содержимым:

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

Это позволяет запустить метод Configure в файле startup.cs, но я по-прежнему получаю те же ошибки.

startup.cs

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

Function2.cs

publi c class Function2 {[FunctionName ("test")] publi c asyn c Task> RunOrchestrator ([OrchestrationTrigger] IDurableOrchestrationContext context) {var output = 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.1 Microsoft. Azure .Functions.Extensions 1.0.0

Microsoft. Azure .WebJobs.Extensions.DurableTask 2.1.1

Microsoft.Extensions.Http 3.1.2

Microsoft. NET .sdk.Функции 3.0. 4

1 Ответ

2 голосов
/ 03 марта 2020

На данный момент попробуйте понизить версию Microsoft. NET .sdk.Functions 3.0.4 до предыдущей версии. Команда сделала некоторые улучшения производительности, но я видел людей, поднимающих ту же проблему (проблемы с DI)

...