CNB Exchange Rate Provider implementation and documentation #775
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implemented Exchange Rate Provider for the Czech National Bank (CNB).
Used .NET 8.0 (LTS) — the current enterprise-supported release.
Key Features
Files
Program.cs :Entry point of the app. Sets up Dependency Injection (DI), logging, configuration, and orchestrates execution. Fetches the CNB payload once, detects decimal style (comma or dot), and prints formatted exchange rates.
Config/AppConfig.cs:
Holds strongly typed configuration (ExchangeRateSettings) with validation rules for the CNB URL, timeout, and currencies list. Ensures misconfiguration fails fast.
Models/Currency.cs: Immutable record representing a three-letter ISO currency code (e.g., EUR, USD).
Models/ExchangeRate.cs: Immutable record representing a rate pair (e.g., EUR/CZK=25.123456). Used to store per-unit rates between two currencies
Services/CnbClient.cs: Handles HTTP requests to the Czech National Bank (CNB) API using HttpClientFactory. Logs timeouts, network errors, and cancellations. Uses HttpTimeoutSeconds from config.
Services/CnbParser.cs: reads the CNB .txt file (pipe-separated). Handles header skipping, trimming, number normalization, and invalid rows. Detects whether the file uses comma or dot decimals (DetectCulture helper).
Services/ExchangeRateProvider.cs: Core business logic. Fetches data via the client, parses it, computes per-unit exchange rates.
Services/ICnbClient.cs, ICnbParser.cs, IExchangeRateProvider.cs: Interfaces for clean architecture and testability.
Appsettings.json: Central configuration file. Defines CNB URL, HTTP timeout, logging levels, and list of currencies to fetch. Can be changed without recompiling.
CNB Sources
-English:
https://www.cnb.cz/en/.../daily.txt(dot decimals)https://www.cnb.cz/cs/.../denni_kurz.txt(comma decimals)