Regardless of whether we should, can we use IHostedService
in an Azure Functions App?
Here is an attempt to register a hosted service (background service, specifically) as IHostedService
:
internal sealed class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddHostedService<ExampleBackgroundService>();
}
}
The Functions App then throws the following exception:
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'