Creating a Worker Service in ASP .NET Core 3.0

How to write background services for modern web applications

Martin Cerruti
The Startup

--

Worker Services are nothing new. They have been around for ages, and chances are you’ve worked on one before. A worker generally performs a periodic background task, such as sending out notification e-mails. Most modern cloud applications run at least a handful of them to ensure smooth sailing. The addition of worker services solidifies the position of the .NET ecosystem as a background development stack.

In ASP.NET, background workers were previously available as Hosted Services, even before the release of .NET Core 3.0. You could simply implement the IHostedService interface, register it in Startupby calling services.AddHostedService<MyHostedService>() and the ASP runtime would take care of the rest for you.

But even though they were supported, having one or multiple hosted services run as a part of your ASP.NET application isn’t exactly idiomatic design. That changed with the release of ASP.NET Core 3.0. There is now a Worker Service template available in Visual Studio, providing a template for independent background workers.

In this article, we’ll dive straight into creating a worker service that periodically sends an e-mail using SendGrid. You’ll learn to use the various ASP.NET…

--

--

Martin Cerruti
The Startup

Software Architect, Technology Writer, but most of all a programmer.