簡體   English   中英

Azure Function 未調用啟動的配置

[英]Azure Function startup's Configure not being called

我正在嘗試在我的 Azure Function projet in .NET 5 (VS 2022) 中創建非靜態函數,並且未調用Startup Configure 方法。

這是我的啟動 class

[assembly: FunctionsStartup(typeof(AuthenticationGateway.Functions.Startup))]
namespace AuthenticationGateway.Functions
{
    class Startup : FunctionsStartup //public or not, still does not get called.
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            
            //break point here never gets hit...
            
        }

        
    }


}

這是有問題的 function:

namespace AuthenticationGateway.Functions
{
    public class CreationConnection
    {
        private AuthenticationGatewayContext Context { get; set; }

        public CreationConnection(AuthenticationGatewayContext context)
        {
            Context = context;
        }

        [Function("CreationConnection")]
        public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequestData req,
            FunctionContext executionContext)
        {            

            var response = req.CreateResponse(HttpStatusCode.OK);

            return response;
        }
    }
}

我已經嘗試評論Configure中的所有代碼,以防萬一它有問題,但也不起作用。 還嘗試將啟動 class 標記為public ,沒有 go。

這是相關項目的依賴項

在此處輸入圖像描述

它們不是 projet 在創建 Azure Function projet 時的默認依賴項,但當我嘗試其他解決方案來解決該問題時,它引導我將它們插入。

這是控制台在啟動項目時所說的內容:

Azure 功能核心工具核心工具版本:3.0.3904 提交 hash:c345f7140a8f968c5dbc621f8a8374d8e3234206(64 位)Function 運行時版本:3.3.1.0

我錯過了什么嗎?

編輯:我已經恢復到以下依賴項,因為之前的依賴項已經完成,因此在項目中找不到任何功能。

在此處輸入圖像描述

頁面上,它說必須安裝以下依賴項:

Microsoft.Azure.Functions.Extensions
Microsoft.NET.Sdk.Functions package version 1.0.28 or later
Microsoft.Extensions.DependencyInjection (currently, only version 3.x and earlier supported)

我已經這樣做了,除了最后一個,因為它似乎與 .NET 5 不兼容。 此外,該項目現在不可構建:

error MSB4062: The "GenerateFunctionMetadata" task could not be loaded from the assembly

我嘗試按照以下步驟重現您遇到的相同問題:

  1. 在 VS2022 中創建了 Azure 函數(堆棧:.Net5-v3)。
  2. 在將Microsoft.Net.Sdk.functions添加到項目之前,已經構建成功。

在此處輸入圖像描述

  1. Microsoft.Net.Sdk.functions添加到項目后,它運行到相同的問題 MSB4062 錯誤如下:

在此處輸入圖像描述

通過引用這些 SO Thread1Thread2 ,刪除Microsoft.Net.Sdk.functions將解決編譯問題。

以防萬一您正在運行 v4,不使用 Startup。

在 Program.cs 中執行依賴注入設置:

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .ConfigureServices(builder =>
    {
        builder.AddTransient<IUserService, UserService>();
        builder.AddTransient<ICompetitionService, CompetitionService>();
        builder.AddTransient<ICompetitionRepository, CompetitionRepository>();
    })
    .Build();

host.Run();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM