Skip to content

SchemaReadyGate

Namespace AgentPrism · Assembly AgentPrism.Abstractions.dll

Delays background services until the SQL schema is ready.

public sealed class SchemaReadyGate

objectSchemaReadyGate

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

The startup service that applies migrations is an IHostedService and waits for them in StartAsync. However, BackgroundService.StartAsync returns without waiting for ExecuteAsync. IHostedService instances start in registration order. If the chain calls .UseMcp before .UseSqlite, the background service can make its first SQL attempt before migrations complete and receive “no such table”.

The gate is independent of registration order. The waiting side does not know the order and waits only for the ready signal. Enforcing an order would be fragile because the consumer writes the chain and no ordering can cover every configuration.

The gate opens automatically when no SQL persistence provider is registered, such as for in-memory stores. Otherwise, background services would wait forever in an in-memory installation.

SchemaReadyGate(IEnumerable<SqlPersistenceRegistrationMarker>)

Section titled “ SchemaReadyGate(IEnumerable<SqlPersistenceRegistrationMarker>)”

Initializes a new instance of the SchemaReadyGate class.

public SchemaReadyGate(IEnumerable<SqlPersistenceRegistrationMarker> registrations)

registrations IEnumerable<SqlPersistenceRegistrationMarker>

The registered SQL persistence providers. If empty, the gate never closes.

ArgumentNullException

registrations is null.

Gets whether the schema is ready.

public bool IsReady { get; }

bool

Marks the schema as ready. The migration startup service calls this method.

public void MarkReady()

Repeated calls are harmless. This method also runs when AutoApplyMigrations is disabled. In that case the consumer is responsible for the schema, and delaying background services has no value.

Waits until the schema is ready.

public Task WaitAsync(CancellationToken cancellationToken)

cancellationToken CancellationToken

The cancellation token for the wait.

Task

A task that completes when the schema is ready.

OperationCanceledException

cancellationToken is cancelled. If migration fails, the host already stops and the waiting service exits through that path.