// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); services.AddServerSideBlazor(); var teslaAppSettings = new TeslaAppSettings(); Configuration.Bind(teslaAppSettings); services.AddSingleton(teslaAppSettings); services.AddSingleton(Configuration); services.AddHttpClient <TeslaApiClient>(client => { client.BaseAddress = teslaAppSettings.TeslaApiClient.BaseAddress; client.Timeout = teslaAppSettings.TeslaApiClient.Timeout; client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue( teslaAppSettings.TeslaApiClient.UserAgent.Name, teslaAppSettings.TeslaApiClient.UserAgent.Version)); }); services.AddScoped <IStorageService, FileStorageService>(); services.AddScoped <TeslaService>(); }
public TeslaApiClient(HttpClient client, TeslaAppSettings appSettings) { this.client = client; this.appSettings = appSettings; }