OpenUrzednik.Nbp.DependencyInjection 1.0.17-preview.g216ea16a82

This is a prerelease version of OpenUrzednik.Nbp.DependencyInjection.
dotnet add package OpenUrzednik.Nbp.DependencyInjection --version 1.0.17-preview.g216ea16a82
                    
NuGet\Install-Package OpenUrzednik.Nbp.DependencyInjection -Version 1.0.17-preview.g216ea16a82
                    
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="OpenUrzednik.Nbp.DependencyInjection" Version="1.0.17-preview.g216ea16a82" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenUrzednik.Nbp.DependencyInjection" Version="1.0.17-preview.g216ea16a82" />
                    
Directory.Packages.props
<PackageReference Include="OpenUrzednik.Nbp.DependencyInjection" />
                    
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 OpenUrzednik.Nbp.DependencyInjection --version 1.0.17-preview.g216ea16a82
                    
#r "nuget: OpenUrzednik.Nbp.DependencyInjection, 1.0.17-preview.g216ea16a82"
                    
#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 OpenUrzednik.Nbp.DependencyInjection@1.0.17-preview.g216ea16a82
                    
#: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=OpenUrzednik.Nbp.DependencyInjection&version=1.0.17-preview.g216ea16a82&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=OpenUrzednik.Nbp.DependencyInjection&version=1.0.17-preview.g216ea16a82&prerelease
                    
Install as a Cake Tool

OpenUrzednik.Nbp.DependencyInjection

🇬🇧 English version

Rejestracja klientów NBP z OpenUrzednik.Nbp w Microsoft.Extensions.DependencyInjection: klienty typowane z IHttpClientFactory, sprawdzane opcje, logowanie i śledzenie.

Część zestawu OpenUrzednik.NET — zobacz główne README po pełny przegląd projektu.

Instalacja

dotnet add package OpenUrzednik.Nbp.DependencyInjection

Użycie

builder.Services.AddOpenUrzednikNbp();
public sealed class RatesService(INbpCurrencyExchangeRateClient rates)
{
    public Task<OpenUrzednikResult<CurrencyExchangeRates>> GetUsdAsync(CancellationToken cancellationToken)
        => rates.GetLatestAsync("USD", cancellationToken: cancellationToken);
}

Rejestrowane są INbpCurrencyExchangeRateClient, INbpExchangeRateTableClient i INbpGoldPriceClient (oraz ich klasy). Wszystkie korzystają z jednego nazwanego HttpClient ("OpenUrzednik.Nbp"). Klienty są rejestrowane jako transient, jak zwykle przy IHttpClientFactory: nie wstrzykuj ich do singletonów, bo taki singleton zatrzyma jeden HttpClient na zawsze i nie zauważy zmian DNS.

Opcje ustawiasz w lambdzie:

builder.Services.AddOpenUrzednikNbp(options =>
{
    options.ApiUrl = "https://proxy.example.com/nbp/";
    options.Timeout = TimeSpan.FromSeconds(10);
});

Błędne opcje (np. adres http://) zatrzymują start aplikacji wyjątkiem OptionsValidationException.

Ponowienia i limity czasu

Pakiet sam nie dodaje ponowień ani limitów czasu. Zwraca IHttpClientBuilder, więc dodajesz je standardowym API Microsoftu z pakietu Microsoft.Extensions.Http.Resilience:

builder.Services.AddOpenUrzednikNbp()
    .AddStandardResilienceHandler();

NbpOptions.Timeout obejmuje wszystkie próby razem, więc jeśli jest krótszy niż łączny limit handlera, przerwie ponowienia. Z handlerem go nie ustawiaj albo daj mu więcej czasu niż handlerowi.

Domyślnie handler ponawia zapytanie do 3 razy przy statusach 5xx, 408 i 429 (z uwzględnieniem Retry-After). Każda próba ma 10 s, całe zapytanie 30 s. Handler ma też circuit breaker i rate limiter. Szczegóły i zmianę ustawień (np. options.Retry.MaxRetryAttempts = 5) opisuje dokumentacja Microsoftu. Dodaj jeden taki handler, nie kilka. Jeśli aplikacja dodaje go już wszystkim klientom przez ConfigureHttpClientDefaults (jak szablon .NET Aspire), nie dodawaj drugiego. Na .NET Framework pakiety Microsoft.Extensions.Http.Resilience 10.x ostrzegają przy kompilacji, że nie wspierają tej platformy.

Gdy handler odrzuci zapytanie, dostajesz błąd w wyniku, a nie wyjątek: przekroczony czas to RequestTimeoutError, a otwarty circuit breaker albo rate limiter to ServiceUnavailableError. Anulowanie przez wywołującego nadal rzuca OperationCanceledException.

Logowanie i śledzenie

Klienty logują przez zarejestrowany ILoggerFactory. Kategorią jest pełna nazwa klienta (np. OpenUrzednik.Nbp.Gold.NbpGoldPriceClient). Spany trafiają do źródła OpenUrzednik.Nbp, które w OpenTelemetry włączysz przez AddSource("OpenUrzednik.*").

Jeśli zarejestrujesz własny TimeProvider albo INbpUrlBuilderFactory, klienty użyją ich zamiast domyślnych.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 is compatible.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.