azure - .netcore Azure 函数启动类未被调用
问题描述
我的 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>();
}
}
}
推荐阅读
- java - OR-Tools / SCIP - 如何使用指标约束来解决 MIP 问题?
- python - 不明白这是对全局变量的不正确语法
- django - Heroku 无法连接到我的 django 数据库
- strapi - Strapi 角色权限生成错误问题
- java - 嵌入式 Kafka 上的空点异常
- python - 将 Dataframe 中的一列与 pandas 中不同大小的另一列进行比较
- python - 使用 DRF 序列化器验证包含动态键的嵌套字典
- java - 如何创建将引用静态文件夹的检票口自定义 CssResourceReference(使用 Spring Boot jar 包装)
- c - c语言中的luhns算法
- c++ - 为什么函数参数的行为类似于变量声明?