Skip to content

AgentPrismServiceCollectionExtensions

Namespace AgentPrism · Assembly AgentPrism.Core.dll

Extensions that register AgentPrism with dependency injection.

public static class AgentPrismServiceCollectionExtensions

objectAgentPrismServiceCollectionExtensions

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

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

public static IAgentPrismBuilder AddAgentPrism(this IHostApplicationBuilder builder)

builder IHostApplicationBuilder

The host application builder.

IAgentPrismBuilder

The configuration chain.

The one call every AgentPrism 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.AddAgentPrism()
.UseOpenAI(builder.Configuration["OpenAI:ApiKey"]!)
.UsePostgreSql(builder.Configuration.GetConnectionString("AgentPrism")!);

ArgumentNullException

builder is null.

AddAgentPrism(IServiceCollection, IConfiguration?)

Section titled “ AddAgentPrism(IServiceCollection, IConfiguration?)”

Adds AgentPrism to the service collection.

public static IAgentPrismBuilder AddAgentPrism(this IServiceCollection services, IConfiguration? configurationSection = null)

services IServiceCollection

Service collection.

configurationSection IConfiguration?

Configuration section settings are read from.

IAgentPrismBuilder

The configuration chain.

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

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

ArgumentNullException

services is null.

AddJobHandler<THandler>(IServiceCollection)

Section titled “ AddJobHandler<THandler>(IServiceCollection)”

Adds an IJobHandler extension point.

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

services IServiceCollection

Service collection.

IServiceCollection

The same collection, for chaining.

THandler

The handler type to add.

Evaluation registers its own handler with this method. TryAddEnumerable is used: if the same type is added twice, only the first counts.

builder.Services.AddJobHandler<NightlyReportJobHandler>();

ArgumentNullException

services is null.

UseScheduling(IServiceCollection, Action<AgentPrismSchedulingOptions>?)

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

Sets batch and scheduled run settings from code.

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

services IServiceCollection

Service collection.

configure Action<AgentPrismSchedulingOptions>?

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 AddAgentPrism; 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.