Implementing the new Worker Service projects
The new Worker Services and the generic hosting in ASP.NET Core 3.0 and later make it pretty easy to create simple service-like applications that can do some stuff without the full blown ASP.NET stack – and without a web server.
You can create this project with the following command:
dotnet new worker -n BackgroundServiceSample -o BackgroundServiceSample
Basically, this creates a console application with Program.cs and Worker.cs in it. The Worker.cs file contains the BackgroundService class. The Program.cs file looks pretty familiar but without WebHostBuilder:
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[]
args) =>
...