Table of Contents

SqliteRateCacheExtensions Class

Definition

Namespace
Bodu.Financial.ExchangeRates
Assembly
Bodu.Financial.ExchangeRates.Caching.Sqlite.dll
Package
Bodu.Financial.ExchangeRates.Caching.Sqlite 1.0.0
Source
SqliteRateCacheExtensions.cs

Provides the fluent registration of a SQLite-backed exchange-rate cache onto an IFinancialServiceBuilder.

public static class SqliteRateCacheExtensions
Inheritance
SqliteRateCacheExtensions
Inherited Members

Methods

AddSqliteRateCache(IFinancialServiceBuilder, string, IConfiguration?, string, Action<SqliteRateCacheOptions>?)

Registers a SqliteRateCache bound to providerName, resolvable as an IRateCache and as a keyed IRateCache under the provider name.

public static IFinancialServiceBuilder AddSqliteRateCache(this IFinancialServiceBuilder builder, string providerName, IConfiguration? configuration = null, string sectionName = "Financial:RateCache:Sqlite", Action<SqliteRateCacheOptions>? configure = null)

Parameters

builder IFinancialServiceBuilder

The financial service builder.

providerName string

The provider whose rates the cache stores.

configuration IConfiguration

An optional configuration root or section bound into SqliteRateCacheOptions.

sectionName string

The configuration section name. Defaults to Financial:RateCache:Sqlite.

configure Action<SqliteRateCacheOptions>

An optional callback applied after configuration binding.

Returns

IFinancialServiceBuilder

The builder, for chaining.

Examples

// One shared database file holding several providers' series, each cache keyed by its provider name.
services.AddFinancialService()
        .AddSqliteRateCache("RBA", configure: o => o.DatabaseFilePath = "/var/cache/fx.db")
        .AddSqliteRateCache("OFX", configure: o => o.DatabaseFilePath = "/var/cache/fx.db")
        .AddSqliteRateCache("XE",  configure: o => o.DatabaseFilePath = "/var/cache/fx.db")
        .AddCachedRateProvider<OfxRateProvider>("OFX",
            cacheFactory: (sp, name) => sp.GetRequiredKeyedService<IRateCache>(name));

// Resolve a specific provider's cache by key, or the first-registered one by default.
var ofxCache = provider.GetRequiredKeyedService<IRateCache>("OFX");

Remarks

The cache is registered as a singleton keyed by providerName so its keep-alive connection and per-pair write locks are shared across resolutions and the container disposes it on shutdown. The bound provider name is also applied to the options so a configuration section need not repeat it. Options are validated through ValidateOnStart, so misconfiguration fails fast at application startup.

Call this once per provider to register several caches side by side. Point them at distinct DatabaseFilePath values to isolate each provider in its own file, or at one shared file to hold every provider's series in a single database - the provider is the leading key column, so the series stay partitioned with no collisions. The first registration also backs the default IRateCache resolution; resolve a specific provider's cache by its key.

Exceptions

ArgumentNullException

Thrown when builder is null.

ArgumentException

Thrown when providerName or sectionName is empty or white space.

Applies to

ProductVersions
.NET8, 10