Muonroi.BackgroundJobs.Abstractions 1.0.0-alpha.16

This is a prerelease version of Muonroi.BackgroundJobs.Abstractions.
dotnet add package Muonroi.BackgroundJobs.Abstractions --version 1.0.0-alpha.16
                    
NuGet\Install-Package Muonroi.BackgroundJobs.Abstractions -Version 1.0.0-alpha.16
                    
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="Muonroi.BackgroundJobs.Abstractions" Version="1.0.0-alpha.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Muonroi.BackgroundJobs.Abstractions" Version="1.0.0-alpha.16" />
                    
Directory.Packages.props
<PackageReference Include="Muonroi.BackgroundJobs.Abstractions" />
                    
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 Muonroi.BackgroundJobs.Abstractions --version 1.0.0-alpha.16
                    
#r "nuget: Muonroi.BackgroundJobs.Abstractions, 1.0.0-alpha.16"
                    
#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 Muonroi.BackgroundJobs.Abstractions@1.0.0-alpha.16
                    
#: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=Muonroi.BackgroundJobs.Abstractions&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Muonroi.BackgroundJobs.Abstractions&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Tool

Muonroi.BackgroundJobs.Abstractions

Contracts and DI wiring for Muonroi background job scheduler integrations — provider-agnostic interfaces that work with Hangfire or Quartz interchangeably.

NuGet License: Apache 2.0

This package ships the shared contracts for the Muonroi background job subsystem: IBackgroundJobScheduler, IMuonroiJobExecutionContext, TenantAwareJobBase, and the AddBackgroundJobs DI extension. It contains no runtime behavior — the actual job processing is provided by the implementation packages (Muonroi.BackgroundJobs.Hangfire or Muonroi.BackgroundJobs.Quartz). Reference this package when authoring job classes or libraries that must remain provider-agnostic.

Installation

dotnet add package Muonroi.BackgroundJobs.Abstractions --prerelease

For a complete setup, also add the provider package:

dotnet add package Muonroi.BackgroundJobs.Hangfire --prerelease
# or
dotnet add package Muonroi.BackgroundJobs.Quartz --prerelease

Quick Start

This package is a contracts-only library. The runtime wiring is performed by the provider package's [ModuleInitializer], which calls BackgroundJobHandler.RegisterProvider before AddBackgroundJobs is invoked.

1. Register in Program.cs (provider package already referenced):

// Muonroi.BackgroundJobs.Hangfire's [ModuleInitializer] registers itself automatically.
// AddBackgroundJobs reads "BackgroundJobConfigs" from appsettings.json and dispatches
// to the registered provider.
builder.Services.AddBackgroundJobs(builder.Configuration);

// Register job classes — Hangfire resolves them from the DI container.
builder.Services.AddTransient<DataCleanupJob>();
builder.Services.AddTransient<ReportEmailJob>();

2. appsettings.json configuration section:

{
  "BackgroundJobConfigs": {
    "JobType": "Hangfire",
    "ConnectionString": null
  }
}

3. Plain job (no tenant context needed):

public sealed class DataCleanupJob(ILogger<DataCleanupJob> logger)
{
    public Task RunAsync()
    {
        logger.LogInformation("[DataCleanupJob] Starting cleanup at {UtcNow:O}", DateTimeOffset.UtcNow);
        // domain work here
        return Task.CompletedTask;
    }
}

4. Tenant-aware job (inherits TenantAwareJobBase):

public sealed class ReportEmailJob(
    ISystemExecutionContextAccessor executionContextAccessor,
    ITenantContextPolicy tenantContextPolicy,
    ILogger<ReportEmailJob> logger)
    : TenantAwareJobBase(executionContextAccessor, tenantContextPolicy)
{
    protected override Task ExecuteAsync()
    {
        ISystemExecutionContext ctx = ExecutionContextAccessor.Get();
        logger.LogInformation("[ReportEmailJob] TenantId={TenantId}", ctx.TenantId);
        return Task.CompletedTask;
    }
}

5. Schedule jobs via IBackgroundJobScheduler:

public class JobsController(IBackgroundJobScheduler scheduler) : ControllerBase
{
    // Fire-and-forget
    [HttpPost("enqueue")]
    public IActionResult Enqueue()
    {
        string id = scheduler.Enqueue<DataCleanupJob>(j => j.RunAsync());
        return Ok(new { jobId = id });
    }

    // Delayed one-shot
    [HttpPost("schedule")]
    public IActionResult Schedule()
    {
        string id = scheduler.Schedule<DataCleanupJob>(
            j => j.RunAsync(),
            DateTimeOffset.UtcNow.AddMinutes(5));
        return Ok(new { jobId = id });
    }

    // Recurring (CRON)
    [HttpPost("recurring")]
    public IActionResult Recurring()
    {
        scheduler.AddOrUpdateRecurring<DataCleanupJob>(
            "daily-cleanup",
            j => j.RunAsync(),
            "0 2 * * *");          // every day at 02:00 UTC
        return NoContent();
    }

    // Cancel recurring
    [HttpDelete("recurring/{id}")]
    public IActionResult RemoveRecurring(string id)
    {
        scheduler.RemoveRecurring(id);
        return NoContent();
    }
}

Features

  • IBackgroundJobScheduler — unified interface for fire-and-forget, delayed, and recurring jobs across providers
  • TenantAwareJobBase — abstract base class that automatically restores IMuonroiJobExecutionContext (tenant ID, user ID, correlation ID) before executing domain logic
  • IMuonroiJobExecutionContext / MuonroiJobExecutionContext — job-scoped execution context carrying tenant, user, and scheduling metadata
  • BackgroundJobHandler.AddBackgroundJobs — single DI extension that reads BackgroundJobConfigs and dispatches to the registered provider
  • BackgroundJobHandler.RegisterProvider — compile-time delegate registry used by provider packages; no reflection, AOT-safe
  • JobProviderRegistration delegate — typed contract for provider self-registration
  • JobType enum — Hangfire | Quartz
  • BackgroundJobConfigs — strongly-typed options bound from the BackgroundJobConfigs configuration section

Configuration

Key Type Default Description
BackgroundJobConfigs:JobType JobType Hangfire Selects the active provider
BackgroundJobConfigs:ConnectionString string? null Passed through to the provider for storage setup

AddBackgroundJobs throws MConfigurationException if JobType has no registered provider (e.g. the provider package is not referenced).

API Reference

Type Purpose
IBackgroundJobScheduler Schedule fire-and-forget, delayed, and recurring jobs
TenantAwareJobBase Base class for jobs requiring tenant/user context restoration
IMuonroiJobExecutionContext Extends ISystemExecutionContext with JobId, JobType, ScheduledAt
MuonroiJobExecutionContext Default sealed implementation of IMuonroiJobExecutionContext
BackgroundJobHandler Static DI helper — AddBackgroundJobs extension + RegisterProvider
JobProviderRegistration delegate IServiceCollection(IServiceCollection, IConfiguration) — provider contract
BackgroundJobConfigs Options class bound from "BackgroundJobConfigs" section
JobType Enum: Hangfire, Quartz

Samples

  • Quickstart.BackgroundJobs — full end-to-end demo: Hangfire in-memory storage, fire-and-forget, delayed, recurring, tenant-aware jobs, and Hangfire dashboard

Compatibility

  • Target framework: net8.0
  • License: Apache-2.0 (OSS)

License

Apache-2.0. See LICENSE-APACHE for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Muonroi.BackgroundJobs.Abstractions:

Package Downloads
Muonroi.AspNetCore

ASP.NET Core integration: auto-CRUD controllers, middleware pipeline, license protection, and Muonroi hosting extensions.

Muonroi.BackgroundJobs.Hangfire

Package Description

Muonroi.BackgroundJobs.Quartz

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-alpha.16 75 6/22/2026
1.0.0-alpha.15 110 5/31/2026
1.0.0-alpha.14 111 5/15/2026
1.0.0-alpha.13 94 5/2/2026
1.0.0-alpha.12 77 4/2/2026
1.0.0-alpha.11 130 4/2/2026
1.0.0-alpha.9 71 3/30/2026
1.0.0-alpha.8 157 3/28/2026
1.0.0-alpha.7 73 3/27/2026
1.0.0-alpha.5 62 3/27/2026
1.0.0-alpha.4 77 3/27/2026
1.0.0-alpha.3 65 3/27/2026
1.0.0-alpha.2 71 3/26/2026
1.0.0-alpha.1 88 3/8/2026