Table of Contents

DistributedRateCacheExtensions Class

Definition

Namespace
Bodu.Financial.ExchangeRates
Assembly
Bodu.Financial.ExchangeRates.Caching.Distributed.dll
Package
Bodu.Financial.ExchangeRates.Caching.Distributed 1.0.0
Source
DistributedRateCacheExtensions.cs

Provides the fluent registration of a distributed (Redis-capable) exchange-rate cache onto an IFinancialServiceBuilder.

public static class DistributedRateCacheExtensions
Inheritance
DistributedRateCacheExtensions
Inherited Members

Methods

AddDistributedRateCache(IFinancialServiceBuilder, string, IConfiguration?, string, Action<DistributedRateCacheOptions>?)

Registers a DistributedRateCache bound to providerName over the IDistributedCache already registered in the container, resolvable as an IRateCache and as a keyed IRateCache under the provider name.

public static IFinancialServiceBuilder AddDistributedRateCache(this IFinancialServiceBuilder builder, string providerName, IConfiguration? configuration = null, string sectionName = "Financial:RateCache:Distributed", Action<DistributedRateCacheOptions>? 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 DistributedRateCacheOptions.

sectionName string

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

configure Action<DistributedRateCacheOptions>

An optional callback applied after configuration binding.

Returns

IFinancialServiceBuilder

The builder, for chaining.

Examples

services.AddStackExchangeRedisCache(o => o.Configuration = "localhost:6379");
services.AddFinancialService()
        .AddDistributedRateCache("RBA");

// Resolve the cache, or wrap a source provider with a CachingRateProvider over it.
var cache = provider.GetRequiredService<IRateCache>();

Remarks

The caller is responsible for registering an IDistributedCache (for example via AddStackExchangeRedisCache or AddDistributedMemoryCache); use AddRedisRateCache(IFinancialServiceBuilder, Action<RedisCacheOptions>, string, IConfiguration?, string, Action<DistributedRateCacheOptions>?) to register a Redis cache and the exchange-rate cache together. The cache is registered as a singleton so its per-pair write locks are shared across resolutions, and is exposed on both the default and the keyed IRateCache surface as the same instance. Options are validated through ValidateOnStart, so misconfiguration fails fast at application startup.

Exceptions

ArgumentNullException

Thrown when builder is null.

ArgumentException

Thrown when providerName or sectionName is empty or white space.

AddRedisRateCache(IFinancialServiceBuilder, Action<RedisCacheOptions>, string, IConfiguration?, string, Action<DistributedRateCacheOptions>?)

Registers a Redis-backed IDistributedCache and a DistributedRateCache over it, bound to providerName, resolvable as an IRateCache and as a keyed IRateCache under the provider name.

public static IFinancialServiceBuilder AddRedisRateCache(this IFinancialServiceBuilder builder, Action<RedisCacheOptions> configureRedis, string providerName, IConfiguration? configuration = null, string sectionName = "Financial:RateCache:Distributed", Action<DistributedRateCacheOptions>? configure = null)

Parameters

builder IFinancialServiceBuilder

The financial service builder.

configureRedis Action<RedisCacheOptions>

The callback configuring the Redis cache connection and options.

providerName string

The provider whose rates the cache stores.

configuration IConfiguration

An optional configuration root or section bound into DistributedRateCacheOptions.

sectionName string

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

configure Action<DistributedRateCacheOptions>

An optional callback applied after configuration binding.

Returns

IFinancialServiceBuilder

The builder, for chaining.

Examples

services.AddFinancialService()
        .AddRedisRateCache("RBA", redis => redis.Configuration = "localhost:6379");

Remarks

A convenience over AddDistributedRateCache(IFinancialServiceBuilder, string, IConfiguration?, string, Action<DistributedRateCacheOptions>?) that first registers a Redis IDistributedCache via AddStackExchangeRedisCache, then registers the exchange-rate cache over it. Use the lower-level AddDistributedRateCache(IFinancialServiceBuilder, string, IConfiguration?, string, Action<DistributedRateCacheOptions>?) directly when the IDistributedCache is registered separately or is not Redis.

Exceptions

ArgumentNullException

Thrown when builder or configureRedis is null.

ArgumentException

Thrown when providerName or sectionName is empty or white space.

Applies to

ProductVersions
.NET8, 10