SchemaReadyGate
AgentPrism.Abstractions.dllDelays background services until the SQL schema is ready.
public sealed class SchemaReadyGateInheritance
Section titled “Inheritance”Inherited Members
Section titled “Inherited Members”object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
Section titled “Remarks”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.
Constructors
Section titled “Constructors”SchemaReadyGate(IEnumerable<SqlPersistenceRegistrationMarker>)
Section titled “ SchemaReadyGate(IEnumerable<SqlPersistenceRegistrationMarker>)”Initializes a new instance of the SchemaReadyGate class.
public SchemaReadyGate(IEnumerable<SqlPersistenceRegistrationMarker> registrations)Parameters
Section titled “Parameters”registrations IEnumerable<SqlPersistenceRegistrationMarker>
The registered SQL persistence providers. If empty, the gate never closes.
Exceptions
Section titled “Exceptions”registrations is null.
Properties
Section titled “Properties”IsReady
Section titled “ IsReady”Gets whether the schema is ready.
public bool IsReady { get; }Property Value
Section titled “Property Value”Methods
Section titled “Methods”MarkReady()
Section titled “ MarkReady()”Marks the schema as ready. The migration startup service calls this method.
public void MarkReady()Remarks
Section titled “Remarks”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.
WaitAsync(CancellationToken)
Section titled “ WaitAsync(CancellationToken)”Waits until the schema is ready.
public Task WaitAsync(CancellationToken cancellationToken)Parameters
Section titled “Parameters”cancellationToken CancellationToken
The cancellation token for the wait.
Returns
Section titled “Returns”A task that completes when the schema is ready.
Exceptions
Section titled “Exceptions”cancellationToken is cancelled. If migration fails,
the host already stops and the waiting service exits through that path.