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) => Â Â ...