Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
lawrence_shaun_introducing_net_maui_build_and_deploy_crosspl.pdf
Скачиваний:
50
Добавлен:
26.06.2023
Размер:
5.15 Mб
Скачать

Chapter 10 Remote Data

builder.Services

.AddRefitClient<IWeatherForecastService>()

.ConfigureHttpClient(c => c.BaseAddress = new Uri("https:// api.openweathermap.org/data/2.5"));

This new line of code makes use of the Refit extension methods that enable you to consume an implementation of IWeatherForecastService whenever you register a dependency on that interface. It is worth reiterating that the implementation for the IWeatherForecastService

is automatically generated for you through the Refit package. For further reading on this package, I thoroughly recommend their website at https://reactiveui.github.io/refit/.

Further Reading

You have added some complexities into your application in order to handle the scenario when webservice access doesn’t load as expected. There are two really great libraries that can really help to reduce the amount of code you need to write around these parts.

Polly

To quote the about section on the GitHub repository,

Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner.

Polly can really help to reduce writing complex code around the failure scenarios of webservice access. I thoroughly recommend checking out the GitHub repository at https://github.com/App-vNext/Polly.

329