Skip to content
Tracon

TraconServiceCollectionExtensions

Namespace Tracon · Assembly Tracon.Core.dll

Extensions that register Tracon with dependency injection.

public static class TraconServiceCollectionExtensions

objectTraconServiceCollectionExtensions

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

AddJobHandler<THandler>(IServiceCollection, string)

Section titled “ AddJobHandler<THandler>(IServiceCollection, string)”

Adds an IJobHandler extension point under a handler key.

public static IServiceCollection AddJobHandler<THandler>(this IServiceCollection services, string handlerKey) where THandler : class, IJobHandler

services IServiceCollection

Service collection.

handlerKey string

The key jobs are dispatched by. 1-128 characters: lowercase ASCII letters, digits, ., _, or -, starting with a letter or digit. Pick a namespace prefix of your own (contoso.nightly-report).

IServiceCollection

The same collection, for chaining.

THandler

The handler type to add.

The worker dispatches by exact, ordinal key match, so this call may appear before or after AddTracon — registration order does not decide which handler runs, and no handler can shadow another.

The handler is registered scoped and resolved from a fresh scope for every execution, so it may take scoped dependencies in its constructor. Registering two handlers under the same key, or using a key inside Tracon’s own tracon. namespace, stops the host from starting.

builder.Services.AddJobHandler<NightlyReportJobHandler>("contoso.nightly-report");

ArgumentNullException

services is null.

ArgumentException

handlerKey is empty, malformed, or inside the JobHandlerKeys.ReservedPrefix namespace.

Adds Tracon to the host application builder and reads settings from the Tracon section.

public static ITraconBuilder AddTracon(this IHostApplicationBuilder builder)

builder IHostApplicationBuilder

The host application builder.

ITraconBuilder

The configuration chain.

The one call every Tracon application starts with. On its own it runs with in-memory stores and needs no database; a provider and a store are added to the chain it returns.

var builder = WebApplication.CreateBuilder(args);
builder.AddTracon()
.UseOpenAI(builder.Configuration["OpenAI:ApiKey"]!)
.UsePostgreSql(builder.Configuration.GetConnectionString("Tracon")!);

ArgumentNullException

builder is null.

AddTracon(IServiceCollection, IConfiguration?)

Section titled “ AddTracon(IServiceCollection, IConfiguration?)”

Adds Tracon to the service collection.

public static ITraconBuilder AddTracon(this IServiceCollection services, IConfiguration? configurationSection = null)

services IServiceCollection

Service collection.

configurationSection IConfiguration?

Configuration section settings are read from.

ITraconBuilder

The configuration chain.

All services are registered with TryAdd. If you register your own implementation before this call, yours wins; Tracon does not overwrite it.

When no additional configuration is done, Tracon runs with in-memory stores and requires no database.

ArgumentNullException

services is null.

UseScheduling(IServiceCollection, Action<TraconSchedulingOptions>?)

Section titled “ UseScheduling(IServiceCollection, Action<TraconSchedulingOptions>?)”

Sets batch and scheduled run settings from code.

public static IServiceCollection UseScheduling(this IServiceCollection services, Action<TraconSchedulingOptions>? configure = null)

services IServiceCollection

Service collection.

configure Action<TraconSchedulingOptions>?

Settings modifier. When not given, only the defaults/configuration apply.

IServiceCollection

The same collection, for chaining.

The job queue and scheduling stores are already registered by AddTracon; this method only changes the settings (e.g. turning off this process’s background worker with o.RunWorker = false). PostConfigure is used, so the value given from code always wins over the value coming from the configuration file.

// A web instance that serves requests and leaves the jobs to a worker process.
builder.Services.UseScheduling(o => o.RunWorker = false);

ArgumentNullException

services is null.