Muonroi.BackgroundJobs.Abstractions
1.0.0-alpha.16
dotnet add package Muonroi.BackgroundJobs.Abstractions --version 1.0.0-alpha.16
NuGet\Install-Package Muonroi.BackgroundJobs.Abstractions -Version 1.0.0-alpha.16
<PackageReference Include="Muonroi.BackgroundJobs.Abstractions" Version="1.0.0-alpha.16" />
<PackageVersion Include="Muonroi.BackgroundJobs.Abstractions" Version="1.0.0-alpha.16" />
<PackageReference Include="Muonroi.BackgroundJobs.Abstractions" />
paket add Muonroi.BackgroundJobs.Abstractions --version 1.0.0-alpha.16
#r "nuget: Muonroi.BackgroundJobs.Abstractions, 1.0.0-alpha.16"
#:package Muonroi.BackgroundJobs.Abstractions@1.0.0-alpha.16
#addin nuget:?package=Muonroi.BackgroundJobs.Abstractions&version=1.0.0-alpha.16&prerelease
#tool nuget:?package=Muonroi.BackgroundJobs.Abstractions&version=1.0.0-alpha.16&prerelease
Muonroi.BackgroundJobs.Abstractions
Contracts and DI wiring for Muonroi background job scheduler integrations — provider-agnostic interfaces that work with Hangfire or Quartz interchangeably.
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 providersTenantAwareJobBase— abstract base class that automatically restoresIMuonroiJobExecutionContext(tenant ID, user ID, correlation ID) before executing domain logicIMuonroiJobExecutionContext/MuonroiJobExecutionContext— job-scoped execution context carrying tenant, user, and scheduling metadataBackgroundJobHandler.AddBackgroundJobs— single DI extension that readsBackgroundJobConfigsand dispatches to the registered providerBackgroundJobHandler.RegisterProvider— compile-time delegate registry used by provider packages; no reflection, AOT-safeJobProviderRegistrationdelegate — typed contract for provider self-registrationJobTypeenum —Hangfire|QuartzBackgroundJobConfigs— strongly-typed options bound from theBackgroundJobConfigsconfiguration 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)
Related Packages
Muonroi.BackgroundJobs.Hangfire— Hangfire provider implementation; references this package and registers itself via[ModuleInitializer]Muonroi.BackgroundJobs.Quartz— Quartz.NET provider implementationMuonroi.Core.Abstractions— providesISystemExecutionContext,ISystemExecutionContextAccessor, andITenantContextPolicyused byTenantAwareJobBaseMuonroi.Tenancy.Core— tenant resolution primitives
License
Apache-2.0. See LICENSE-APACHE for details.
| Product | Versions 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. |
-
net8.0
- Muonroi.Core.Abstractions (>= 1.0.0-alpha.16)
- Muonroi.Tenancy.Core (>= 1.0.0-alpha.16)
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.Quartz
Package Description |
|
|
Muonroi.BackgroundJobs.Hangfire
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.16 | 72 | 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 | 93 | 5/2/2026 |
| 1.0.0-alpha.12 | 77 | 4/2/2026 |
| 1.0.0-alpha.11 | 129 | 4/2/2026 |
| 1.0.0-alpha.9 | 71 | 3/30/2026 |
| 1.0.0-alpha.8 | 156 | 3/28/2026 |
| 1.0.0-alpha.7 | 73 | 3/27/2026 |
| 1.0.0-alpha.5 | 61 | 3/27/2026 |
| 1.0.0-alpha.4 | 75 | 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 |