Reference

AddPersistedOperationStore

Package Trax.Api.GraphQL.PersistedOperationsNamespaces Trax.Api.GraphQL.PersistedOperations.Extensions, Trax.Api.GraphQL.PersistedOperations.ConfigurationSource ServiceCollectionPersistedOperationsExtensions.cs, PersistedOperationStoreBuilder.cs

Registers IPersistedOperationStore and IPersistedOperationsService on a host that does not serve GraphQL: a CI manifest uploader, admin tooling, a console client. Declared on the static class ServiceCollectionPersistedOperationsExtensions; configure receives a PersistedOperationStoreBuilder.

Signatures

public static IServiceCollection AddPersistedOperationStore(
    this IServiceCollection services,
    Action<PersistedOperationStoreBuilder> configure);
 
// Obsolete: a compile error.
public static IServiceCollection AddPersistedOperationStore(
    this IServiceCollection services,
    string databaseConnectionString);
 
// Obsolete.
public static IServiceCollection AddPersistedOperationStore(
    this IServiceCollection services,
    string databaseConnectionString,
    string rabbitMqInvalidationConnectionString);
 
public sealed class PersistedOperationStoreBuilder
{
    public PersistedOperationStoreBuilder UseRabbitMqInvalidation(string connectionString);
    public PersistedOperationStoreBuilder SingleNode();
    public PersistedOperationStoreBuilder GateManagement(string? policy = null, string? roles = null);
    public PersistedOperationStoreBuilder GateManagementToAuthenticatedUsers();
}

Parameters

ParameterTypeDescription
servicesIServiceCollectionThe service collection. The host also registers the Trax data layer (AddTrax(t => t.AddEffects(e => e.UsePostgres(...)))), which the store reads and writes through
configureAction<PersistedOperationStoreBuilder>Says how a change made through the store reaches the GraphQL nodes
PersistedOperationStoreBuilder methodDescription
UseRabbitMqInvalidation(connectionString)Broadcast every change over the broker the GraphQL nodes use with their own UseRabbitMqInvalidation, so each empties its caches. Throws ArgumentException for a blank connection string
SingleNode()Declare that no other process caches these operations: this one serves them itself, or nothing serves them while it writes. Nothing checks the claim; a GraphQL node elsewhere sees a change only when its cached entry reaches its maximum age
GateManagement(policy, roles)Declare who may manage documents through this process's surfaces, the dashboard's pages. The same rules as UsePersistedOperations' GateManagement: a policy or roles is required, a comma-separated role list is any of, repeated calls are all of. Without it the dashboard shows no management pages. Code calling the service with no person behind it is not gated
GateManagementToAuthenticatedUsers()Let any authenticated person manage documents through the dashboard. Prefer GateManagement

Returns

The same IServiceCollection.

Behavior

  • Throws ArgumentNullException for a null argument, and InvalidOperationException when configure calls neither builder method or calls both. Both are thrown when AddPersistedOperationStore runs.
  • The one-string overload is a compile error; called through reflection it throws as if configure did nothing. The two-string overload ignores the first string and forwards to store => store.UseRabbitMqInvalidation(rabbitMqInvalidationConnectionString).
  • Called alongside UsePersistedOperations in one host, the GraphQL registration's validator replaces the no-op one.
  • Called alongside UsePersistedOperations in one host, UsePersistedOperations' options are the ones in force, whichever call comes first: its gate, enforcement and invalidation. A store that declares no gate takes that one. A store whose GateManagement differs from the one UsePersistedOperations declares refuses the host at startup, naming both calls.

Registered services

ServiceLifetimeImplementation
PersistedOperationsOptionsSingleton (TryAdd)Built with SingleNode() or the broker; UsePersistedOperations replaces it
IPersistedOperationStoreSingletonDbPersistedOperationStorage
IPersistedOperationsServiceSingleton (TryAdd)The shared management service
IPersistedOperationsManagementGateScoped (TryAdd)The declared management gate, evaluated with the caller's services
IPersistedOperationValidatorSingleton (TryAdd)NoOpPersistedOperationValidator
IPersistedOperationCacheSingleton (TryAdd)A no-op cache
IPersistedOperationBroadcasterSingleton (TryAdd)RabbitMQ with UseRabbitMqInvalidation, a no-op with SingleNode
TimeProviderSingleton (TryAdd)TimeProvider.System

Example

services.AddPersistedOperationStore(store =>
    store.UseRabbitMqInvalidation(rabbitMqConnectionString).GateManagement(roles: "Deployer")
);

See also