FdbDatabaseProvider

Namespace: FoundationDB.DependencyInjection · class

Implements: IFdbDatabaseProvider, IFdbDatabaseScopeProvider, IDisposable

Provides access to a FoundationDB database instance

Constructors

FdbDatabaseProvider

FdbDatabaseProvider(IOptions<FdbDatabaseProviderOptions> optionsAccessor)

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.

ProviderOptions

FdbDatabaseProviderOptions ProviderOptions { get; }

Options used to configure this provider

Root

FdbDirectorySubspaceLocation Root { get; }

Path to the root of the database

Methods

Create

static IFdbDatabaseProvider Create(FdbDatabaseProviderOptions options)

CreateScope

IFdbDatabaseScopeProvider<TState> CreateScope<TState>(Func<IFdbDatabase, CancellationToken, Task<(IFdbDatabase, TState)>> 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.

SetDatabase

void SetDatabase(IFdbDatabase db, Exception e)

Sets or clears the current IFdbDatabase singleton that will be returned by this provider

Start

void Start()

Start connecting to the database

Stop

void Stop()

Abort all pending transactions using the current database instance

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