QuartzNET.Extend 1.0.0

dotnet add package QuartzNET.Extend --version 1.0.0
                    
NuGet\Install-Package QuartzNET.Extend -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="QuartzNET.Extend" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="QuartzNET.Extend" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="QuartzNET.Extend" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add QuartzNET.Extend --version 1.0.0
                    
#r "nuget: QuartzNET.Extend, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package QuartzNET.Extend@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=QuartzNET.Extend&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=QuartzNET.Extend&version=1.0.0
                    
Install as a Cake Tool

Quartz.NET.Extend

NuGet Version License

Developed by Mustafa Kamal

A revolutionary Quartz.NET extension that enables inline job scheduling with full runtime management capabilities.

🚀 Technical Overview

Quartz.NET.Extend transforms job scheduling by:

  • Eliminating boilerplate: No need for separate IJob implementations
  • Contextual scheduling: Define jobs right where they're needed in business logic
  • Runtime control: Edit or delete schedules without application restart
  • Type-safe arguments: Pass complex objects directly to jobs
  • DI integration: Automatic service resolution via IServiceProvider

🆚 Traditional vs Extended Approach

Traditional IJob Implementation

// Separate class required
public class ActivationReminderJob : IJob 
{
    private readonly ISendEmail _emailService;
    
    public ActivationReminderJob(ISendEmail emailService) 
    {
        _emailService = emailService;
    }

    public async Task Execute(IJobExecutionContext context)
    {
        var data = (SimpleDataStructure)context.MergedJobDataMap["args"];
        await _emailService.SendEmailAsync($"{data.Value} => {DateTime.Now}");
    }
}

// Scheduling code elsewhere
var job = JobBuilder.Create<ActivationReminderJob>()
    .UsingJobData("args", new SimpleDataStructure { Value = "Welcome message" })
    .Build();

await scheduler.ScheduleJob(job, 
    TriggerBuilder.Create()
        .WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(7, 53))
        .Build());

With Quartz.NET.Extend

[Route("RegisterNewUser")]
[HttpPost]
public async Task<IActionResult> RegisterNewUser()
{
    string databaseRecordKey = 1001.ToString();

    await QuartzWrapper.addToJobs(async (sp, arg) =>
    {
        var emailService = sp.GetRequiredService<ISendEmail>();
        var data = arg as SimpleDataStructure;
        await emailService.SendEmailAsync($"{data.Value} => {DateTime.Now}");
    },
    identifier: "send reminder mail to new user for account activation",
    instanceKey: databaseRecordKey,
    codeCustomArgument: new SimpleDataStructure { 
        Value = "Welcome Mustafa, please Activate your mail" 
    },
    CronScheduleBuilder.DailyAtHourAndMinute(7, 53));

    return Ok(new { Message = "User registered successfully" });
}

Quartz.NET.Extend Workflow Diagram
Figure 1: Inline Job Scheduling Architecture

🧠 Technical Deep Dive

Quartz.NET.Extend transforms job scheduling by:

  • Runtime Code Generation: Uses Roslyn to compile lambdas into IJob implementations
  • Contextual Binding: Ties jobs to business entities via instanceKey
  • Type-Safe Marshaling: Serializes arguments using System.Text.Json
  • Dynamic Schedule Management: Edits triggers without app restart
  • DI-Aware Execution: Resolves services via IServiceProvider

📦 Installation

Prerequisite Packages

Install-Package Quartz
Install-Package Quartz.Extensions.DependencyInjection
Install-Package Quartz.Extensions.Hosting
Install-Package Quartz.Serialization.Json
Install-Package Microsoft.CodeAnalysis.Common
Install-Package Microsoft.CodeAnalysis.CSharp

Program.cs Configuration

using Quartz.NET.Extend;

// ... existing builder configuration ...

if (builder.Environment.IsDevelopment())
{
    await QuartzWrapper.RegisterCodeAsync();
}

var app = builder.Build();

app.Services.AddQuartzServices(rescheduleAlreadyActiveJobs: false);

if (app.Environment.IsDevelopment())
{
    await QuartzWrapper.RemoveAllJobsAsync();
}
else 
{
    QuartzWrapper.RescheduleAlreadyActiveJobsAsync().GetAwaiter().GetResult();
}

🛠 API Reference

Job Management

// Create job with cron expression
public static async Task addToJobs(
    Func<IServiceProvider, object, Task> jobDelegate,
    string identifier,
    string instanceKey,
    object codeCustomArgument,
    string cronExpression,
    TimeSpan delay = default)

// Edit existing job
public static async Task EditJob(
    string identifier,
    string instanceKey,
    object newArgument,
    TimeSpan newInterval)

// Delete job
public static async Task DeleteJob(
    string identifier, 
    string instanceKey)

🌍 Real-World Examples

E-Commerce Order Processing

[HttpPost]
public async Task PlaceOrder(Order order)
{
    await _orderService.Create(order);

    // Abandoned cart reminder
    await QuartzWrapper.addToJobs(async (sp, arg) => 
    {
        var order = arg as Order;
        var cartService = sp.GetRequiredService<ICartService>();
        if (!await cartService.IsCompleted(order.Id))
        {
            await sp.GetRequiredService<INotificationService>()
                   .SendReminder(order.UserId);
        }
    },
    identifier: "abandoned-cart-reminder",
    instanceKey: order.Id.ToString(),
    codeCustomArgument: order,
    CronScheduleBuilder.DailyAtHourAndMinute(20, 0));
}

IoT Device Monitoring

public async Task RegisterDevice(Device device)
{
    // Health check every 5 minutes
    await QuartzWrapper.addToJobs(async (sp, arg) =>
    {
        var device = arg as Device;
        var healthChecker = sp.GetRequiredService<IDeviceMonitor>();
        await healthChecker.CheckStatus(device.Id);
    },
    identifier: "device-health-check",
    instanceKey: device.MacAddress,
    codeCustomArgument: device,
    interval: TimeSpan.FromMinutes(5));
}

Newsletter System

public async Task ScheduleNewsletter(Newsletter newsletter, DateTime sendTime)
{
    await QuartzWrapper.addToJobs(async (sp, arg) =>
    {
        var newsletter = arg as Newsletter;
        await sp.GetRequiredService<IMailingService>()
               .SendBulk(newsletter);
    },
    identifier: "newsletter-delivery",
    instanceKey: newsletter.Id.ToString(),
    codeCustomArgument: newsletter,
    CronScheduleBuilder.DailyAtHourAndMinute(sendTime.Hour, sendTime.Minute));
}

📜 License

MIT © 2025 Mustafa Kamal

Key Features Highlighted:

  • Clear comparison between traditional and new approaches
  • Complete installation instructions
  • Ready-to-use configuration snippet
  • API reference table
  • Badges for version and license
  • Clean markdown formatting for GitHub

Would you like me to add any additional sections such as:

  • Advanced configuration options
  • Troubleshooting guide
  • Performance benchmarks
  • Contribution guidelines?
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 180 4/19/2025