Skip to main content

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.

ParameterTypeDescription
servicesIServiceCollectionThe service collection to configure.
configureAction<ZeridionFlareOptions>Action to set configuration options.
ReturnsIServiceCollectionThe service collection for chaining.
ThrowsArgumentExceptionWhen ApiKey is empty or whitespace.

What gets registered

ServiceLifetimeDescription
IOptions<ZeridionFlareOptions>SingletonConfiguration options bound from the configure delegate.
JobTypeRegistrySingletonAssembly scanner that discovers IJob<T> and IRecurringJob implementations.
IJob<TPayload> (per type)TransientEach discovered payload job, registered as its interface.
Concrete recurring job typesTransientEach discovered IRecurringJob, registered as its class.
FlareAuthHandlerTransientDelegatingHandler that sets Authorization: Bearer {ApiKey} on every request.
FlareApiClientTransientTyped HttpClient with FlareAuthHandler and Polly resilience (retry on 5xx).
IJobClientSingletonThe FlareJobClient implementation for enqueuing jobs.
JobExecutorSingletonExecutes jobs in DI scopes with timeout enforcement.
FlareWorkerServiceHostedBackground 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/json default header
  • FlareAuthHandler that sets Authorization: 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.

ParameterTypeDescription
hostIHostThe built host to validate.
ReturnsIHostThe host for chaining.
ThrowsInvalidOperationExceptionWhen 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