I created a .NET 5, Visual Studio project using the Worker Service template, which creates a Program.cs
file containing the Program
class with the following method:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<Worker>();
});
Since I want to specify a Startup
class to implement health checks for this application (since it will be deployed to Kubernetes (I’m following this tutorial)), I read there’s the ConfigureWebHostDefaults extension method. However, I get the following error trying to use it:
The code that gives me the error is the following (the one hidden by the error in the above screenshot):
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); })
This answer seemed to show my situation, but the Microsoft.Extensions.Hosting.Abstractions
package doesn’t resolve the issue. I also tried to import the Microsoft.AspNetCore.Hosting
and Microsoft.AspNetCore.Hosting
packages, without success. I’m already using the Microsoft.Extensions.Hosting
package.