Raain.Worker 1.0.5

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

Raain.Worker

Raain.Worker is a shared .NET library for managing background jobs using Hangfire, designed to be used by API projects. It allows you to register recurring and fire-and-forget jobs dynamically from your API, and exposes a Hangfire dashboard for monitoring.


Features

  • Register recurring jobs (sync or async) from your API project.
  • Enqueue fire-and-forget jobs.
  • Expose Hangfire Dashboard in your API.
  • Fully compatible with dependency injection.

Getting Started

Prerequisites

  • .NET SDK 8.0+ installed
  • NuGet 6.0+ (comes with .NET SDK)
  • PostgreSQL
  • Hangfire

Example Usage

Configuring App Constants (RaainWorkerConstOptions)

Your application can override default constants provided by the Raain.Worker package at runtime.

1. Override Specific Values

Use RaainWorkerConst.Configure to override only the properties you need:

using Raain.Worker.Shared.Consts;

// Override some defaults in Program.cs
RaainWorkerConst.Configure(opts =>
{
    opts.WorkerPath = "/worker";
    opts.WorkerDefaultTimezone = "UTC";
    opts.ApiKeyHeader = "X-My-Api-Key";
});
  • Only the values you set will be replaced; all other defaults remain intact.
  • Safe to call multiple times in different modules or initialization code.

2. Replace the Entire Options Object

You can create a full custom AppConstOptions instance and replace the defaults entirely:

var customOptions = new RaainWorkerConstOptions
{
    WorkerPath = "/worker";
    WorkerDefaultTimezone = "UTC";
    ApiKeyHeader = "X-My-Api-Key";
};

// In Program.cs
RaainWorkerConst.SetOptions(customOptions);

Or with class:

public class AppConst: RaainAppConstOptions
{
    // =======================
    // App & System Defaults
    // =======================
    public override string WorkerPath { get; set; } = "/worker";
    ... Other options

// In Program.cs
RaainWorkerConst.SetOptions(new AppConst());
  • This approach replaces all defaults, so make sure to set all required properties.
  • Useful if you want to inject completely different defaults from your app configuration.

3. Accessing Configured Values

Anywhere in your application, you can read the configured values:

string workerPath = RaainWorkerConst.Options.WorkerPath;
string workerDefaultTimezone = RaainWorkerConst.Options.WorkerDefaultTimezone;

Dependencies Setup

Raain.Worker provides a consistent pattern to register services and middlewares across your application. The convention is:

  • Dependency Injection (services): Add[Package][Feature]()
  • Middleware / pipeline configuration: Use[Package][Feature]()

Below is a summary of common modules and how to set them up.

Add/Register Worker

using Raain.Worker.Shared.Interface;

namespace Api.Workers;

public class EmailWorker : IRaainWorker
{
    public void Execute()
    {
        Console.WriteLine($"EmailWorker executed at {DateTime.Now}");
    }
}

var workerService = app.Services.GetRequiredService<IRaainWorkerSchedulerService>();
await workerService.DeleteWorkerAsync("EmailWorker");

Add/Register Fire-And-Forget Worker

// In ConfigureServices
services.AddRaainAuth(Configuration);

// In Configure / middleware pipeline
app.UseRaainAuth();

Delete Worker

var workerService = app.Services.GetRequiredService<IRaainWorkerSchedulerService>();
await workerService.DeleteWorkerAsync("EmailWorker");
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

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.5 140 2/8/2026