Table of Contents

YahooFinancialServiceBuilderExtensions Class

Definition

Namespace
Bodu.Financial.ExchangeRates
Assembly
Bodu.Financial.ExchangeRates.Yahoo.dll
Package
Bodu.Financial.ExchangeRates.Yahoo 0.7.1
Source
YahooFinancialServiceBuilderExtensions.cs

Provides the fluent registration of the Yahoo Finance exchange-rate provider onto an IFinancialServiceBuilder.

public static class YahooFinancialServiceBuilderExtensions
Inheritance
YahooFinancialServiceBuilderExtensions
Inherited Members

Fields

HttpClientName

The name of the HttpClient configured for Yahoo Finance requests.

public const string HttpClientName = "Bodu.Financial.ExchangeRates.Yahoo"

Field Value

string

Methods

AddYahooExchangeRates(IFinancialServiceBuilder, IConfiguration?, string, Action<YahooRateProviderOptions>?, Action<HttpStandardResilienceOptions>?)

Registers the Yahoo Finance exchange-rate provider, binding its options and configuring a named HttpClient for chart requests.

public static IFinancialServiceBuilder AddYahooExchangeRates(this IFinancialServiceBuilder builder, IConfiguration? configuration = null, string sectionName = "Financial:Yahoo", Action<YahooRateProviderOptions>? configure = null, Action<HttpStandardResilienceOptions>? configureResilience = null)

Parameters

builder IFinancialServiceBuilder

The financial service builder.

configuration IConfiguration

An optional configuration root or section. When supplied, the section named sectionName is bound into YahooRateProviderOptions.

sectionName string

The configuration section name. Defaults to Financial:Yahoo.

configure Action<YahooRateProviderOptions>

An optional callback applied after configuration binding.

configureResilience Action<HttpStandardResilienceOptions>

An optional callback applied to the standard HTTP resilience options after the provider defaults have been set, allowing the retry, timeout, and circuit-breaker behavior to be tuned or effectively disabled.

Returns

IFinancialServiceBuilder

The builder, for chaining.

Remarks

The provider is registered as a singleton so its in-memory store of fetched pairs is shared across resolutions; it is backed by an IHttpClientFactory client so handler lifetime is managed by the factory. The provider is also exposed as IDatedRateProvider and IRateProvider through idempotent registrations.

The named HttpClient is fitted with the standard Polly resilience handler (retry with exponential backoff and jitter, a per-attempt timeout, a total-request timeout, and a circuit breaker), enabled by default and tunable through configureResilience. The handler sits in the message-handler pipeline below the provider's single-flight load coordinator, so a retry re-issues the one in-flight request rather than multiplying across coalesced callers. Because the resilience handler enforces its own per-attempt timeout driven from HttpTimeout, the Timeout is set to InfiniteTimeSpan so the two timeout mechanisms do not compete.

IServiceCollection services = new ServiceCollection();

services
    .AddFinancialService(configuration)
    .AddYahooExchangeRates(
        configuration,
        configure: options => options.UserAgent = "my-app/1.0",
        configureResilience: resilience => resilience.Retry.MaxRetryAttempts = 2);

Exceptions

ArgumentNullException

Thrown when builder is null.

ArgumentException

Thrown when sectionName is empty or white space.

Applies to

ProductVersions
.NET8, 10