oddstech.common.exchangerates 1.0.3

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package oddstech.common.exchangerates --version 1.0.3
                    
NuGet\Install-Package oddstech.common.exchangerates -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="oddstech.common.exchangerates" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="oddstech.common.exchangerates" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="oddstech.common.exchangerates" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add oddstech.common.exchangerates --version 1.0.3
                    
#r "nuget: oddstech.common.exchangerates, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package oddstech.common.exchangerates@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=oddstech.common.exchangerates&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=oddstech.common.exchangerates&version=1.0.3
                    
Install as a Cake Tool

OddsTech.Common.ExchangeRates

A high-performance exchange rate caching and retrieval library for managing currency conversion rates. Supports Redis caching with SQL Server fallback for reliable and fast rate lookups.

Features

  • High-Performance Caching: Redis-based caching for sub-millisecond exchange rate lookups
  • Database Fallback: Automatic fallback to SQL Server when cache is unavailable
  • Currency Conversion: Built-in currency conversion with support for EUR as base currency
  • Resilient: Automatic cache population on miss with error handling
  • Performance Monitoring: Optional performance metrics logging
  • Type-Safe: Full nullable reference type support
  • Thread-Safe: Designed for concurrent access in multi-threaded environments

Installation

dotnet add package oddstech.common.exchangerates

Quick Start

1. Configuration

Add to your appsettings.json:

{
  "ExchangeRate": {
    "DatabaseConnectionString": "Server=...;Database=Payments;...",
    "RedisConnectionString": "localhost:6379",
    "RedisKeyPrefix": "exchangeRates:",
    "CacheExpirationHours": 24,
    "EnableDatabaseFallback": true,
    "EnablePerformanceMetrics": false,
    "GetAllExchangeRatesProcedure": "payments.sp_GetAllExchangeRates",
    "DatabaseTimeoutSeconds": 30
  }
}

2. Register Services

using oddstech.common.exchangerates.Extensions;

// In Startup.cs or Program.cs
builder.Services.AddExchangeRateServices(
    builder.Configuration.GetSection("ExchangeRate"));

3. Use the Service

public class PaymentService
{
    private readonly IExchangeRateService _exchangeRateService;

    public PaymentService(IExchangeRateService exchangeRateService)
    {
        _exchangeRateService = exchangeRateService;
    }

    public async Task ProcessPayment()
    {
        // Get single exchange rate
        var usdRate = await _exchangeRateService.GetExchangeRateAsync("USD");
        Console.WriteLine($"1 EUR = {usdRate.Rate} USD");

        // Get all exchange rates
        var allRates = await _exchangeRateService.GetAllExchangeRatesAsync();

        // Convert amount between currencies
        var convertedAmount = await _exchangeRateService.ConvertAmountAsync(
            amount: 100m,
            fromCurrency: "USD",
            toCurrency: "GBP");

        // Sync rates from database to cache
        var syncedCount = await _exchangeRateService.SyncExchangeRatesAsync();
    }
}

Architecture

Components

  1. IExchangeRateService: High-level service with automatic fallback logic
  2. IExchangeRateRepository: Redis cache operations
  3. IExchangeRateDatabaseRepository: SQL Server database operations
  4. ExchangeRate Model: Strongly-typed exchange rate data

Data Flow

Request → Service → Cache (Redis)
                      ↓ (miss)
                   Database (SQL Server)
                      ↓
                   Cache Update

Configuration Options

Option Description Default
DatabaseConnectionString SQL Server connection string Required
RedisConnectionString Redis connection string Required
RedisKeyPrefix Prefix for Redis keys exchangeRates:
CacheExpirationHours Cache TTL in hours (null = no expiry) 24
EnableDatabaseFallback Enable DB fallback on cache miss true
EnablePerformanceMetrics Log performance metrics false
GetAllExchangeRatesProcedure Stored procedure name payments.sp_GetAllExchangeRates
DatabaseTimeoutSeconds Database operation timeout 30

Database Schema

The stored procedure payments.sp_GetAllExchangeRates should return:

SELECT 
    CurrencyId,      -- int
    TargetCurrency,  -- string (e.g., 'USD', 'GBP')
    Rate,            -- decimal (rate relative to EUR)
    IsCanSync,       -- bool
    IsCrypto         -- bool
FROM ConfigCurrencies

Performance

  • Cache Hit: < 1ms typical
  • Cache Miss + DB: < 50ms typical
  • Batch Operations: Optimized for multiple concurrent requests
  • Thread-Safe: Lock-free implementation for maximum throughput

Error Handling

The library provides comprehensive error handling:

  • Cache failures trigger automatic database fallback
  • Database failures are logged but don't stop cache operations
  • All exceptions include detailed context for debugging
  • Graceful degradation when services are unavailable

Best Practices

  1. Cache Warming: Call SyncExchangeRatesAsync() on startup
  2. Scheduled Sync: Periodically sync rates (e.g., hourly via background job)
  3. Performance Monitoring: Enable metrics in non-production environments
  4. Connection Pooling: Use connection pooling for SQL Server
  5. Redis Persistence: Configure Redis with RDB/AOF for durability

Testing

The package includes comprehensive tests:

  • Unit Tests: Repository and service layer tests
  • Integration Tests: Redis and SQL Server integration
  • BDD Tests: End-to-end scenarios using Reqnroll

Run tests:

dotnet test

License

MIT License - See LICENSE file for details

Support

For issues and questions:

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated