A robust ASP.NET Core Web API demonstrating how to integrate Quartz.NET for scheduling background jobs, alongside Entity Framework Core and a SQLite database to manage a notification system.
The application automatically generates a "Scheduled Job Fired" notification every minute in the background using Quartz, and provides a full RESTful API to retrieve, manage, and delete these notifications.
- Background Jobs with Quartz.NET: Implements a
NotificationJobthat runs on a Cron schedule (every 1 minute) to automatically generate notifications. - RESTful Notification API: Full CRUD operations for managing notifications (Create, Read, Update, Delete) with filtering and convenience endpoints (like Mark As Read).
- Lightweight Database: Uses SQLite via Entity Framework Core, meaning no heavy database setup is required. The database (
notifications.db) is automatically created and migrated on startup. - Modern API Documentation: Uses Scalar API Reference for clean, modern OpenAPI documentation.
- Framework: .NET / ASP.NET Core
- Job Scheduling: Quartz.NET
- ORM: Entity Framework Core
- Database: SQLite
- API Documentation: Scalar (
Scalar.AspNetCore)
Controllers/- Contains theNotificationsControllerexposing the REST API endpoints.Models/- Data models (e.g.,Notification.cs) representing the database schema.DTOs/- Data Transfer Objects used for creating and updating notifications.Jobs/- Contains the Quartz.NET background jobs (e.g.,NotificationJob.cs).Data/- Contains the Entity FrameworkAppDbContext.
- .NET SDK (Version 8.0 or later recommended)
- Clone or download the repository.
- Navigate to the
QuartzNETproject directory. - Run the application using the .NET CLI:
dotnet run
- The application will automatically create the
notifications.dbSQLite database if it doesn't exist. - Open your browser and navigate to the Scalar API documentation (usually at
https://localhost:<port>/scalar/v1) to explore and test the endpoints.
The API provides the following endpoints under /api/notifications:
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/notifications |
Get all notifications. Supports optional ?userId={id} and ?isRead={bool} filters. |
GET |
/api/notifications/{id} |
Get a specific notification by ID. |
POST |
/api/notifications |
Create a new notification manually. |
PUT |
/api/notifications/{id} |
Update an existing notification. |
PATCH |
/api/notifications/{id}/read |
Convenience endpoint to mark a specific notification as read. |
DELETE |
/api/notifications/{id} |
Delete a specific notification by ID. |
DELETE |
/api/notifications?userId={id} |
Delete all notifications for a specific user. |
The NotificationJob is configured in Program.cs and uses a Cron schedule expression: 0 0/1 * * * ? (runs every 1 minute).
Each time the job executes, it writes a new notification to the database indicating that the scheduled job fired, including the exact UTC timestamp. This job uses the [DisallowConcurrentExecution] attribute to prevent multiple instances of the job running simultaneously if execution takes longer than the scheduled interval.