为什么永远不会调用在我的 Function App 启动时注入的 DelegatingHandler 上的 SendAsync?
Why would SendAsync on my DelegatingHandler injected in Startup of my Function App never be called?
我对使用 .Net 3.1 的 Azure Function App 进行了以下配置:
public override void Configure(IFunctionsHostBuilder builder)
{
Config = CdrConfigurationBuilder.BuildConfiguration<Startup>(approotpath: builder.GetContext().ApplicationRootPath);
builder.Services.AddSingleton(Config);
builder.Services.AddAzureAppConfiguration();
builder.Services.AddSingleton(CdrConfigurationBuilder.ConfigurationRefresher);
builder.Services.AddSingleton((c) => new AuthHeaderHandler(Config, apisection: string.Empty, securitysection: "CDR:Services:Security"));
builder.Services.AddHttpClient<IHtmlDocumentService, HtmlDocumentService>()
.AddHttpMessageHandler<AuthHeaderHandler>()
.SetHandlerLifetime(TimeSpan.FromMinutes(5))
.AddPolicyHandler(GetRetryPolicy());
builder.Services.AddSingleton<IHtmlDocumentService, HtmlDocumentService>();
builder.Services.AddLogging();
}
这会编译并运行,但我的 AuthHeaderHandler
上的 SendAsync()
从未被调用。
我错过了什么?
您正在注射 IHtmlDocumentService
两次。
第二次注册覆盖第一次注册。
删除代码行builder.Services.AddSingleton<IHtmlDocumentService, HtmlDocumentService>();
我对使用 .Net 3.1 的 Azure Function App 进行了以下配置:
public override void Configure(IFunctionsHostBuilder builder)
{
Config = CdrConfigurationBuilder.BuildConfiguration<Startup>(approotpath: builder.GetContext().ApplicationRootPath);
builder.Services.AddSingleton(Config);
builder.Services.AddAzureAppConfiguration();
builder.Services.AddSingleton(CdrConfigurationBuilder.ConfigurationRefresher);
builder.Services.AddSingleton((c) => new AuthHeaderHandler(Config, apisection: string.Empty, securitysection: "CDR:Services:Security"));
builder.Services.AddHttpClient<IHtmlDocumentService, HtmlDocumentService>()
.AddHttpMessageHandler<AuthHeaderHandler>()
.SetHandlerLifetime(TimeSpan.FromMinutes(5))
.AddPolicyHandler(GetRetryPolicy());
builder.Services.AddSingleton<IHtmlDocumentService, HtmlDocumentService>();
builder.Services.AddLogging();
}
这会编译并运行,但我的 AuthHeaderHandler
上的 SendAsync()
从未被调用。
我错过了什么?
您正在注射 IHtmlDocumentService
两次。
第二次注册覆盖第一次注册。
删除代码行builder.Services.AddSingleton<IHtmlDocumentService, HtmlDocumentService>();