Implementing the new Worker Service projects
The 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 a Program.cs
and a Worker.cs
file in it. The Worker.cs
file contains the Worker
class that inherits from the BackgroundService
class. In ASP.NET 5.0 and earlier, the Program.cs
file looks pretty familiar to what we saw in the previous versions of ASP.NET Core but without a WebHostBuilder
:
public class Program { public static void Main(string[] args) { CreateHostBuilder(args).Build().Run(); } ...