Table of Contents

Class DatabaseOptions

Namespace
Tharga.MongoDB.Configuration
Assembly
Tharga.MongoDB.dll

All database options are optional.

public record DatabaseOptions : IEquatable<DatabaseOptions>
Inheritance
DatabaseOptions
Implements
Inherited Members

Properties

ActionEvent

Event triggered on database actions performed on disk.

public Action<ActionEventArgs> ActionEvent { get; set; }

Property Value

Action<ActionEventArgs>

AllowDelayedCommit

Controls whether CommitAsync(bool, CancellationToken) may succeed for a lease whose lock has expired, provided no other writer has touched the document since (the LockKey atomicity check still drives the safety guarantee). Default true. Set to false to restore the strict-TTL behaviour where every expired commit throws LockExpiredException. Individual collections can pin themselves to either policy by overriding the virtual AllowDelayedCommit property on LockableRepositoryCollectionBase<TEntity, TKey>.

public bool AllowDelayedCommit { get; set; }

Property Value

bool

AssureIndex

Enable or disable the assurance of incexes. By default, indexes are assured.

public AssureIndexMode AssureIndex { get; set; }

Property Value

AssureIndexMode

AutoRegisterCollections

If true, all classes inheriting from IRepositoryCollection will be registered. This value is default true. Use 'RegisterCollections' in 'DatabaseOptions' to register repositories manually.

public bool AutoRegisterCollections { get; set; }

Property Value

bool

AutoRegisterRepositories

If true, all classes inheriting from IRepository will be registered. This value is default true. Use IServiceCollection to register repositories manually.

public bool AutoRegisterRepositories { get; set; }

Property Value

bool

AutoRegistrationAssemblies

Override the list of assemblies scanned for automatic registration of IRepository and IRepositoryCollection. By default, only assemblies whose name starts with the same prefix as the entry-point assembly are scanned. Assemblies from external NuGet packages are NOT included by default — use AddAutoRegistrationAssembly(Assembly) to add them without replacing the default scan.

public IEnumerable<Assembly> AutoRegistrationAssemblies { get; set; }

Property Value

IEnumerable<Assembly>

ConfigurationLoader

When provided this will override values in appsettings.json. Values in 'Configurations' will be used if they exist, otherwise the values in root will be used. Configuration order:

  1. Named values from Configurations.
  2. Values from the root in Configuration.
  3. Named values from MongoDB-section in appsettings.json.
  4. Values from the root in MongoDB-section in appsettings.json.
  5. Default values.
public Func<IServiceProvider, Task<MongoDbConfigurationTree>> ConfigurationLoader { get; set; }

Property Value

Func<IServiceProvider, Task<MongoDbConfigurationTree>>

ConnectionStringLoader

This function can be provided to dynamically provide a connection string for a specific configuration. If it is not assigned or returns null, the configuration will be read from IConfiguration.

public Func<ConfigurationName, IServiceProvider, Task<ConnectionString>> ConnectionStringLoader { get; set; }

Property Value

Func<ConfigurationName, IServiceProvider, Task<ConnectionString>>

DefaultConfigurationName

The name of the connection string that will be used to read from appsettings.json or from ConnectionStringLoader. If not provided 'Default' will be used.

public string DefaultConfigurationName { get; set; }

Property Value

string

GuidStorageFormat

Controls how Guid values are stored in MongoDB. Standard (RFC 4122) is the default. Use CSharpLegacy only when working with existing legacy data. Individual properties can override this with [FlexibleGuid(GuidStorageFormat.X)].

public GuidStorageFormat GuidStorageFormat { get; set; }

Property Value

GuidStorageFormat

Limiter

Configure database execution limiter.

public ExecuteLimiterOptions Limiter { get; set; }

Property Value

ExecuteLimiterOptions

Monitor

Configuration for monitor. This is by default enabled.

public MonitorOptions Monitor { get; set; }

Property Value

MonitorOptions

ReadyCallback

Optional callback that defers the monitor cache load until the system is ready. When set, the monitor starts immediately (API is usable) but the cache load is postponed until the provided callback action is invoked. The cache is loaded at most once, even if the callback is invoked multiple times. Example usage:

o.ReadyCallback = (serviceProvider, onReady) =>
{
    var config = serviceProvider.GetService<IMyConfig>();
    config.ConfigurationUpdatedEvent += async (_, _) =>
    {
        if (config.HasConfiguration) await onReady();
    };
};
public Action<IServiceProvider, Func<Task>> ReadyCallback { get; set; }

Property Value

Action<IServiceProvider, Func<Task>>

RegisterCollections

Provide manual registration of collections.

public IEnumerable<CollectionType> RegisterCollections { get; set; }

Property Value

IEnumerable<CollectionType>

Methods

AddAutoRegistrationAssembly(Assembly)

Add additional assemblies for auto registration of IRepository and IRepositoryCollection.

public void AddAutoRegistrationAssembly(Assembly assembly)

Parameters

assembly Assembly