Download an ASP.NET Core hosted service which is written in .NET 6.
The code demonstrates how to set up a hosted service, either by inheriting the
IHostedService interface, or the
BackgroundService abstract class. It also has sample code to fire off a task in a background service.
The background services have been added to the DI container through the
IServiceCollection interface, and use dependency injection using the service lifetimes available.
This is the software that will need to be installed onto your machine.
- Visual Studio 2022 17.0.4 or above. It will work with the free community version. Please note, this project will not work with VS 2019.
- .NET 6.0 SDK 6.0.101 or above. Visual Studio 2022 should already have the .NET SDK installed.
Get the application working
These are the steps to get the application working.
- Fill out the source code form. We will send you an email where you can download the source code.
You are now ready to go.
Open the project in Visual Studio
RoundTheCode.HostedServiceExample.sln in Visual Studio 2022.
Start the project in Visual Studio.
The hosted services will start once the project has been launched. See the console application as it sends information through the
ILogger instance in the hosted service.
https://localhost:8002 to test that the web application is working.
Watch our video where we create and configure hosted services in an ASP.NET Core web application.