To make it easier to change the external weather service and to make the code more testable, we will create an interface for the service. Here's how we go about it:
- In the Weather project, create a new folder and name it Services.
- Create a new public interface and name it IWeatherService.
- Add a method for fetching data based on the location of the user, as shown in the following code. Name the method GetForecast:
public interface IWeatherService { Task<Forecast> GetForecast(double latitude, double longitude); }
When we have an interface, we can create an implementation for it by going through the following steps:
- In the Services folder, create a new class with the name OpenWeatherMapWeatherService ...