private void Tick(object state) { try { var api = new ExternalApi(); var updateList = api.FetchDataFromExternalApi().Result; if (updateList != null) { _companyRepository.MergeUpdateList(updateList).Wait(); } } finally { _timer?.Change(Interval, Timeout.Infinite); } }
private static void PopulateDb(IHost host) { using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var companyRepository = services.GetRequiredService <ICompanyRepository>(); var api = new ExternalApi(); var updateList = api.FetchDataFromExternalApi().Result; if (updateList != null) { companyRepository.MergeUpdateList(updateList).Wait(); } } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred populating the DB."); } } }