DistributedRateCacheExtensions Class
Definition
- Namespace
- Bodu.Financial.ExchangeRates
- Assembly
- Bodu.Financial.ExchangeRates.Caching.Distributed.dll
- Package
- Bodu.Financial.ExchangeRates.Caching.Distributed 1.3.0
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
builderIFinancialServiceBuilderThe financial service builder.
providerNamestringThe provider whose rates the cache stores.
configurationIConfigurationAn optional configuration root or section bound into DistributedRateCacheOptions.
sectionNamestringThe configuration section name. Defaults to
Financial:RateCache:Distributed.configureAction<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 keyed by
providerName, so its per-pair write locks are shared across resolutions, and is exposed on
the keyed IRateCache surface under that name. Options are validated through
ValidateOnStart, so misconfiguration fails fast at application startup.
Call this once per provider to register several caches side by side over one IDistributedCache: each provider gets its own cache, bound to its own name, and its entries are written under keys that carry that name. The first registration also backs the default IRateCache resolution; resolve a specific provider's cache by its key.
Exceptions
- ArgumentNullException
Thrown when
builderis null.- ArgumentException
Thrown when
providerNameorsectionNameis 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
builderIFinancialServiceBuilderThe financial service builder.
configureRedisAction<RedisCacheOptions>The callback configuring the Redis cache connection and options.
providerNamestringThe provider whose rates the cache stores.
configurationIConfigurationAn optional configuration root or section bound into DistributedRateCacheOptions.
sectionNamestringThe configuration section name. Defaults to
Financial:RateCache:Distributed.configureAction<DistributedRateCacheOptions>An optional callback applied after configuration binding.
Returns
- IFinancialServiceBuilder
The builder, for chaining.
Examples
services.AddFinancialService()
.AddRedisRateCache(redis => redis.Configuration = "localhost:6379", "RBA");
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
builderorconfigureRedisis null.- ArgumentException
Thrown when
providerNameorsectionNameis empty or white space.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |