https://github.com/fkucukkara/backgroundjobs101
This project demonstrates the usage of different types of hosted services in an ASP.NET Core application
https://github.com/fkucukkara/backgroundjobs101
background-jobs netcore webapi-core
Last synced: about 1 year ago
JSON representation
This project demonstrates the usage of different types of hosted services in an ASP.NET Core application
- Host: GitHub
- URL: https://github.com/fkucukkara/backgroundjobs101
- Owner: fkucukkara
- License: mit
- Created: 2025-02-09T12:07:56.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-05-01T10:12:28.000Z (about 1 year ago)
- Last Synced: 2025-05-01T11:20:05.084Z (about 1 year ago)
- Topics: background-jobs, netcore, webapi-core
- Language: C#
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BackgroundJobs101
This project demonstrates the usage of different types of hosted services in an ASP.NET Core application. It includes examples of timed hosted services, scoped processing services, and queue processing using channels.
## Project Structure
- **API/Program.cs**: Configures the web application and registers the hosted services.
- **API/BackgroundProcessors/HostedService.cs**: A timed hosted service that logs a message at regular intervals.
- **API/BackgroundProcessors/ScopedProcessingService.cs**: A scoped processing service that performs work in a loop until cancellation.
- **API/BackgroundProcessors/ConsumeScopedServiceHostedService.cs**: A background service that consumes the scoped processing service.
- **API/BackgroundProcessors/QueueProcessor.cs**: A background service that processes messages from a channel.
## How to Run
1. Clone the repository:
```sh
git clone https://github.com/fkucukkara/backgroundjobs101.git
cd src\API
```
2. Build and run the application:
```sh
dotnet build
dotnet run
```
3. Use the following endpoint to push messages to the queue:
```sh
GET /push
```
## Services
### HostedService
A simple timed hosted service that logs a message every 5 seconds.
### ScopedProcessingService
A scoped service that performs work in a loop until the cancellation token is triggered.
### ConsumeScopedServiceHostedService
A background service that creates a scope and consumes the `ScopedProcessingService`.
### QueueProcessor
A background service that reads messages from a channel and processes them.
## License
[](LICENSE)
This project is licensed under the MIT License, which allows you to freely use, modify, and distribute the code. See the [`LICENSE`](LICENSE) file for full details.