Raain.Worker
1.0.5
dotnet add package Raain.Worker --version 1.0.5
NuGet\Install-Package Raain.Worker -Version 1.0.5
<PackageReference Include="Raain.Worker" Version="1.0.5" />
<PackageVersion Include="Raain.Worker" Version="1.0.5" />
<PackageReference Include="Raain.Worker" />
paket add Raain.Worker --version 1.0.5
#r "nuget: Raain.Worker, 1.0.5"
#:package Raain.Worker@1.0.5
#addin nuget:?package=Raain.Worker&version=1.0.5
#tool nuget:?package=Raain.Worker&version=1.0.5
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 | 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
- Hangfire (>= 1.8.18)
- Hangfire.AspNetCore (>= 1.8.18)
- Hangfire.MemoryStorage (>= 1.8.1.2)
- Hangfire.PostgreSql (>= 1.20.12)
- Serilog (>= 4.0.0)
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 |