Skip to content

Introduction

Build, schedule and operate source-generated background jobs with Immediate.Handlers.

2 min read
Immediate.Jobs GitHub repository Immediate.Jobs license

Immediate.Jobs is a reflection-free background job scheduler built on Immediate.Handlers. A job is an ordinary handler marked with [Job]; source generation adds a typed scheduler, JSON metadata, an execution adapter and DI registration. The runtime supplies delayed and recurring work, queues, retries, workflows, monitoring and durable storage providers.

Prerequisites and installation

Jobs target net8.0, net9.0, net10.0 and net11.0 and require Immediate.Handlers. Install the main package in the project that declares the handlers:

dotnet add package Immediate.Jobs --prerelease

Choose a durable provider before production; in-memory storage is the automatic default when no provider is selected.

Your first job

SendWelcomeEmail.cs
using Immediate.Handlers.Shared;
using Immediate.Jobs.Shared;

[Handler, Job(Name = "send-welcome-email", MaxAttempts = 5, Timeout = "00:02:00")]
public sealed partial class SendWelcomeEmail(IEmailSender sender)
{
	public sealed record Payload(Guid UserId, string Template);

	private ValueTask HandleAsync(Payload payload, CancellationToken cancellationToken) =>
		new(sender.SendAsync(payload.UserId, payload.Template, cancellationToken));
}

public sealed class SignupService(SendWelcomeEmail.Scheduler welcomeEmail)
{
	public ValueTask<JobHandle> EnqueueAsync(Guid userId, CancellationToken cancellationToken) =>
		welcomeEmail.EnqueueAsync(new(userId, "v2"), cancellationToken);
}

Register handlers and jobs, then inject the generated scoped scheduler:

Program.cs
builder.Services.AddMyAppHandlers();
builder.Services.AddMyAppJobs(options => options.UseInMemory());

The injected type is SendWelcomeEmail.Scheduler. The returned JobHandle is an opaque identifier for monitoring and continuations—not evidence that the job completed.

Where to go next