AddZeridionFlare & UseZeridionFlare
Two extension methods that bootstrap Zeridion Flare in your application. AddZeridionFlare registers all services into the DI container, and UseZeridionFlare validates the configuration at startup.
Namespace: Zeridion.Flare · Assembly: Zeridion.Flare.dll
public static class ZeridionFlareServiceExtensions
{
public static IServiceCollection AddZeridionFlare(
this IServiceCollection services,
Action<ZeridionFlareOptions> configure);
public static IHost UseZeridionFlare(this IHost host);
}
AddZeridionFlare
public static IServiceCollection AddZeridionFlare(
this IServiceCollection services,
Action<ZeridionFlareOptions> configure);
Registers all Zeridion Flare services into the DI container. Call this in your Program.cs during service registration.
| Parameter | Type | Description |
|---|---|---|
services | IServiceCollection | The service collection to configure. |
configure | Action<ZeridionFlareOptions> | Action to set configuration options. |
| Returns | IServiceCollection | The service collection for chaining. |
| Throws | ArgumentException | When ApiKey is empty or whitespace. |
What gets registered
| Service | Lifetime | Description |
|---|---|---|
IOptions<ZeridionFlareOptions> | Singleton | Configuration options bound from the configure delegate. |
JobTypeRegistry | Singleton | Assembly scanner that discovers IJob<T> and IRecurringJob implementations. |
IJob<TPayload> (per type) | Transient | Each discovered payload job, registered as its interface. |
| Concrete recurring job types | Transient | Each discovered IRecurringJob, registered as its class. |
FlareAuthHandler | Transient | DelegatingHandler that sets Authorization: Bearer {ApiKey} on every request. |
FlareApiClient | Transient | Typed HttpClient with FlareAuthHandler and Polly resilience (retry on 5xx). |
IJobClient | Singleton | The FlareJobClient implementation for enqueuing jobs. |
JobExecutor | Singleton | Executes jobs in DI scopes with timeout enforcement. |
FlareWorkerService | Hosted | Background poll loop that claims and executes jobs. |
Assembly scanning
AddZeridionFlare scans assemblies for classes implementing IJob<T> and IRecurringJob. By default, it scans the entry assembly. To scan additional assemblies, set JobAssemblies:
builder.Services.AddZeridionFlare(options =>
{
options.ApiKey = builder.Configuration["Zeridion:ApiKey"]!;
options.JobAssemblies = new[]
{
typeof(Program).Assembly,
typeof(MyJobLibrary.SendEmail).Assembly
};
});
The scanner handles ReflectionTypeLoadException gracefully — if an assembly has types that fail to load, the scanner skips them and continues.
HTTP client resilience
The FlareApiClient is registered as a typed HttpClient with:
- Base URL set to
ZeridionFlareOptions.ApiBaseUrl Accept: application/jsondefault headerFlareAuthHandlerthat setsAuthorization: Bearer {ApiKey}on every request- Standard resilience handler (via
Microsoft.Extensions.Http.Resilience) with Polly-based retry for transient 5xx errors
UseZeridionFlare
public static IHost UseZeridionFlare(this IHost host);
Validates that AddZeridionFlare was called during service registration. Call this after building the host to catch configuration errors at startup instead of at runtime.
| Parameter | Type | Description |
|---|---|---|
host | IHost | The built host to validate. |
| Returns | IHost | The host for chaining. |
| Throws | InvalidOperationException | When AddZeridionFlare was not called. |
Note that UseZeridionFlare extends IHost, not IApplicationBuilder. This means it works with any .NET host — web apps, Worker Services, console apps with the generic host.
Minimal API example
The most common setup for an ASP.NET Core web application:
using Zeridion.Flare;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddZeridionFlare(options =>
{
options.ApiKey = builder.Configuration["Zeridion:ApiKey"]!;
});
var app = builder.Build();
app.UseZeridionFlare();
app.MapPost("/send-email", async (EmailRequest req, IJobClient jobs) =>
{
var jobId = await jobs.EnqueueAsync<SendWelcomeEmail>(
new NewUserEvent { Email = req.Email, Name = req.Name });
return Results.Accepted(value: new { job_id = jobId });
});
app.Run();
Worker Service example
For a standalone Worker Service that only processes jobs (no HTTP endpoints):
using Zeridion.Flare;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddZeridionFlare(options =>
{
options.ApiKey = builder.Configuration["Zeridion:ApiKey"]!;
options.ConcurrencyLimit = 20;
options.PollInterval = TimeSpan.FromSeconds(1);
});
var host = builder.Build();
host.UseZeridionFlare();
host.Run();
This creates a long-running process that polls for jobs and executes them. No controllers, no endpoints — just a background worker. Deploy it as a Windows Service, systemd unit, or container.
Local development
Point the SDK at a locally running Flare API for development:
builder.Services.AddZeridionFlare(options =>
{
options.ApiKey = "zf_test_sk_local_development_key";
options.ApiBaseUrl = "http://localhost:5000";
});
See also
- ZeridionFlareOptions — all configuration properties
- Quick Start — end-to-end setup walkthrough
- Configuration guide — detailed configuration options