azure - .net core Azure Functions启动类未被调用

标签 azure .net-core azure-functions

我的 Azure 函数不会本地调用启动类。 运行项目时,我的断点没有命中 DependencyRegistrations.Register 函数。

包 Microsoft.Azure.Functions.Extensions 已正确安装

using Microsoft.Azure.Functions.Extensions.DependencyInjection;

[assembly: FunctionsStartup(typeof(MyNamespace.Startup))]

namespace MyNamespace
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            DependencyRegistrations.Register(builder.Services);
        }
    }
}

enter image description here

为什么启动类没有被调用?

最佳答案

有两件事我在您的代码片段中没有看到。

1- [程序集:FunctionsStartup(typeof(MyNamespace.Startup))]

2-您确定 nuget 软件包已正确安装吗? (Microsoft.Azure.Functions.Extensions)

最终的启动代码应如下所示:

using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;

[assembly: FunctionsStartup(typeof(MyNamespace.Startup))]

namespace MyNamespace
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddHttpClient();

            builder.Services.AddSingleton<IMyService>((s) => {
                return new MyService();
            });

            builder.Services.AddSingleton<ILoggerProvider, MyLoggerProvider>();
        }
    }
}

关于azure - .net core Azure Functions启动类未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63997086/

相关文章:

database - 如何在 JSON 模板中将子网添加到另一个资源组中的 vnet

.net-core - 在 Mac OS 和 Ubuntu 上安装 .net core 时出错

c# - 静态属性和构造函数注入(inject)潜在的内存泄漏

c# - .NET Core 中的 Mongo C# 驱动程序和 ObjectID JSON 字符串格式

azure-functions - Angular 7 PWA + Azure Functions Gateway Timeout 504 仅使用 Https

php - 将大文件从 azure 网站上传到 azure blob

azure - 如何比较两个获取元数据的输出

azure - terraform Azure 应用程序中不需要参数 active_directory

c# - 未在 root/bin 中找到 Azure Functions 共享 DLL

powershell - 如何更改 Add-Blob Azure cmdlet 的超时值?