Demystifying the new .NET Core 3 Worker Service

Developer Support

Premier Developer Consultant Randy Patterson discusses the benefits of using the new Worker Service project template introduced in .NET Core 3.

.NET Core 3 introduced a new project template called Worker Service. This template is designed to give you a starting point for cross-platform services. As an alternate use case, it sets up a very nice environment for general console applications that is perfect for containers and microservices.

Some of the benefits of using this template include the following areas.

Dependency Injection

The Worker Service template configures a default Dependency injection container, ready for us to use. This is a huge benefit compared to the generic Console template.

Adding Services involves updating the ConfigureServices method in the Program.cs file:

   .ConfigureServices((hostContext, services) =>



The same configuration providers setup for ASP.NET Core are duplicated here for Worker Services. This gives us a powerful and familiar environment for storing configuration information:

  1. appsettings.json
  2. appsettings.{Environment}.json
  3. User Secrets (for development only)
  4. Environment Variables
  5. Command Line arguments

For additional information on each of the providers please see my previous article posted here.


Likewise, logging providers have been configured to match the default setup for ASP.Net Core, giving you the following providers:

  1. Console
  2. Debug
  3. EventSource
  4. EventLog (only when running on Windows)

You can modify the logging providers by adding a ConfigureLogging method to the Host object in Program.cs:

   .ConfigureServices((hostContext, services) =>
   .ConfigureLogging(logging =>

For additional information on logging, please see the documentation for ASP.NET Core.

Worker Startup Class

Finally, the Worker.cs file is where the bulk of your code will exist. There are 3 overridable methods from the base class BackgroundService that let you tie into the lifecycle of your application:

ExecuteAsync – an abstract method used as the main entry point for your application. If this method exits, then your application shuts down.

StartAsync – A virtual method that, when overridden, is called when the service is starting, and can be used for one-time setup of resources.

StopAsync – A virtual method that is called when the application is shutting down, and is a good place to release resources and dispose objects.


The new worker service template in .NET Core 3 creates a hosting environment that is well-suited for console applications, microservices, containerized applications, and cross-platform background services. While these benefits can be configured independently of the template, the Worker Service template gives us a consistent startup environment between ASP.NET Core and Console applications.



Discussion is closed. Login to edit/delete existing comments.

  • Tarik Guney 0

    Can you please remove the HTML tags from the code snippets?

  • Steve Dunn 1

    > ExecuteAsync – an abstract method used as the main entry point for your application. If this method exits, then your application shuts down

    This doesn’t appear to be true any more. I have an empty ExecuteAsync method and when it finishes, the application still runs.

Feedback usabilla icon