无论我们是否应该这样做,我们能在Azure Functions应用程序中使用IHostedService吗?
以下是尝试将托管服务(特别是后台服务)注册为IHostedService的方法:
以下是尝试将托管服务(特别是后台服务)注册为IHostedService的方法:
internal sealed class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddHostedService<ExampleBackgroundService>();
}
}
功能应用程序随后抛出以下异常:
Microsoft.Azure.WebJobs.Script.InvalidHostServicesException: 'The following service registrations did not match the expected services:
[Invalid] ServiceType: Microsoft.Extensions.Hosting.IHostedService, Lifetime: Singleton, ImplementationType: ExampleBackgroundService'