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

Chapter 10 Remote Data

public WeatherWidgetViewModel(WeatherForecastService weatherForecastService)

{

this.weatherForecastService = weatherForecastService;

LoadWeatherCommand = new Command(async () => await LoadWeatherForecast());

Task.Run(async () => await LoadWeatherForecast());

}

This means that when a load fails for whatever reason, the user will have the option to press the retry button and the widget will attempt to load the weather details again. It will walk through the states you added, so the UI will show the different UI options to the user as this happens.

This type of failure handling is considered manual. There are ways to automatically handle retries through a package called Polly.

Simplifying Webservice Access

The previous sections covered how you can interact directly with a web service at the most basic level. It requires a bit of setup but thankfully in your scenario this wasn’t too complicated. Some web services can require a lot more setup or even return a lot more data.

When building your applications, the aim is to write as little code as possible as it reduces the amount of code you need to maintain. This

statement isn’t advocating for writing shortened code that can be difficult for a human to understand but instead stating that you want to focus on the details that are core to the application that you are building and not things like consuming a web service. Sure, you want to know that you are but having to write the underlying bits through the use of HttpClient can become cumbersome. Thankfully there are packages out there that can help you!

326