public async Task SeedAsync(ServiceListContext context, IWebHostEnvironment env, IOptions <ServiceListSettings> settings, ILogger <ServiceListContextSeed> logger)
        {
            context.Database.EnsureCreated();

            var policy = CreatePolicy(logger, nameof(ServiceListContextSeed));

            await policy.ExecuteAsync(async() =>
            {
                var useCustomizationData = settings.Value.UseCustomizationData;
                var contentRootPath      = env.ContentRootPath;
                var picturePath          = env.WebRootPath;

                if (!context.ServiceListItems.Any())
                {
                    await context.ServiceListItems.AddRangeAsync(useCustomizationData
                        ? GetServiceListItemsFromFile(contentRootPath, context, logger)
                        : GetPreconfiguredItems());

                    await context.SaveChangesAsync();
                }
            });
        }
        private IEnumerable <ServiceListItem> GetServiceListItemsFromFile(string contentRootPath, ServiceListContext context, ILogger <ServiceListContextSeed> logger)
        {
            string csvFileServiceListItems = Path.Combine(contentRootPath, "Setup", "ServiceListItems.csv");

            if (!File.Exists(csvFileServiceListItems))
            {
                return(GetPreconfiguredItems());
            }

            string[] csvheaders;
            try
            {
                string[] requiredHeaders = { "name", "description", "price" };
                csvheaders = GetHeaders(csvFileServiceListItems, requiredHeaders, null);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "EXCEPTION ERROR: {Message}", ex.Message);
                return(GetPreconfiguredItems());
            }

            return(File.ReadAllLines(csvFileServiceListItems)
                   .Skip(1)      // skip header row
                   .Select(row => Regex.Split(row, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"))
                   .SelectTry(column => CreateServiceListItem(column, csvheaders))
                   .OnCaughtException(ex => { logger.LogError(ex, "EXCEPTION ERROR: {Message}", ex.Message); return null; })
                   .Where(x => x != null));
        }