Table of Contents

ServiceProviderExtensions Class

Definition

Namespace
Bodu.Financial
Assembly
Bodu.Financial.DependencyInjection.dll
Package
Bodu.Financial.DependencyInjection 1.3.0
Source
ServiceProviderExtensions.cs

Provides the connector that promotes the container-registered ICurrencyLookup to the ambient CurrencyResolution default, so the runtime-tagged Money reads currency metadata through the application's configured catalog.

public static class ServiceProviderExtensions
Inheritance
ServiceProviderExtensions
Inherited Members

Methods

UseCurrencyResolution(IServiceProvider)

Installs the container's ICurrencyLookup as the process-wide ambient currency resolver. Call once at start-up, after the service provider is built, when a custom lookup should back the currency metadata runtime Money reports and the ISO codes its parsers accept.

public static IServiceProvider UseCurrencyResolution(this IServiceProvider provider)

Parameters

provider IServiceProvider

The built service provider.

Returns

IServiceProvider

The same provider, for chaining.

Remarks

This is a composition-root operation: it mutates process-wide state via SetDefault(ICurrencyLookup). Omitting the call leaves the registry-backed default in place, so existing applications behave identically without it. Construction of a runtime Money always takes its precision from the shipped CurrencyRegistry, whichever lookup is installed.

IServiceProvider provider = services
    .AddFinancialService(b => b.AddCurrencyLookup<MyCurrencyLookup>())
    .Services
    .BuildServiceProvider();

// Make the container's ICurrencyLookup back runtime Money metadata and parsing.
provider.UseCurrencyResolution();

Exceptions

ArgumentNullException

provider is null.

InvalidOperationException

No ICurrencyLookup is registered, for example because AddFinancialService was not called.

Applies to

ProductVersions
.NET8, 10