FdbDatabaseSingletonProvider<TState>

Namespace: FoundationDB.DependencyInjection · class

Implements: IFdbDatabaseScopeProvider<TState>, IFdbDatabaseScopeProvider, IDisposable

Default implementation of a scope provider that uses a pre-initialized database instance

Constructors

FdbDatabaseSingletonProvider<TState>

FdbDatabaseSingletonProvider<TState>(IFdbDatabase db, TState state, CancellationTokenSource lifetime)

Properties

Cancellation

CancellationToken Cancellation { get; }

Cancellation token that is tied to the lifetime of this scope

It will become cancelled if the scope (or one of its parents) is stopped.

IsAvailable

bool IsAvailable { get; }

If true, the database instance is ready. If false, the provider is either not started, or the connection is still pending.

Parent

IFdbDatabaseScopeProvider Parent { get; }

Returns the parent scope (or null if this is the top-level scope)

Root

FdbDirectorySubspaceLocation Root { get; }

Path to the root of the database

Methods

CreateScope

IFdbDatabaseScopeProvider<TNewState> CreateScope<TNewState>(Func<IFdbDatabase, CancellationToken, Task<(IFdbDatabase, TNewState)>> start, CancellationToken lifetime = null)

Create a scope that will use the database provided by this instance, and which also needs to perform some initialization steps before being ready (ex: using the DirectoryLayer to open subspaces, ...)

  • start — Handler that will be called AFTER the database becomes ready, but BEFORE any consumer of this scope can run.
  • lifetime — Optional cancellation token that can be used to externally abort the new scope

Dispose

void Dispose()

GetDatabase

ValueTask<IFdbDatabase> GetDatabase(CancellationToken ct = null)

Returns the database instance, once it is ready

During the startup of the application, the task returned will wait until the database becomes ready. After that, the task will immediately return the database singleton.

GetDatabaseAndState

ValueTask<(IFdbDatabase, TState)> GetDatabaseAndState(CancellationToken ct = null)

Return both the underlying database and the scope's State, once they are ready

GetState

ValueTask<TState> GetState(IFdbReadOnlyTransaction tr)

Return the scope's State, once it is ready.

TryGetDatabase

bool TryGetDatabase(out IFdbDatabase db)

Returns the database instance, if it is ready

  • db — Receives the database instance, if it is ready.

Returns: true if the database is ready; otherwise, false, in which case the caller should call GetDatabase and await the task.

This method is for advanced optimizations, that allows the caller to obtain the database handler in a non-async context, allowing the use of ReadOnlySpan or Span parameters.

Calling this will not attempt to auto-start the connection

TryGetDatabaseAndState

bool TryGetDatabaseAndState(out IFdbDatabase db, out TState state)

Returns both the underlying database and the scope's State, if they are ready

  • db — Receives the database instance, if it is ready.
  • state — Receives the scope's state, if it is ready.

Returns: true if the database is ready; otherwise, false, in which case the caller should call GetDatabaseAndState and await the task.

This method is for advanced optimizations, that allows the caller to obtain the database handler in a non-async context, allowing the use of ReadOnlySpan or Span parameters.

Calling this will not attempt to auto-start the connection

TryGetState

bool TryGetState(IFdbReadOnlyTransaction tr, out TState state)

Returns the scope's State, if it is ready.

Returns: true if the state is ready; otherwise, false, in which case the caller should call GetState and await the task.

This method is for advanced optimizations, that allows the caller to obtain the database handler in a non-async context, allowing the use of ReadOnlySpan or Span parameters.

Calling this will not attempt to auto-start the connection