我的 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);
}
}
}
为什么启动类没有被调用?
最佳答案
有两件事我在您的代码片段中没有看到。
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/