| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Linq; |
| | | 4 | | using Microsoft.Extensions.Options; |
| | | 5 | | using System.Threading.Tasks; |
| | | 6 | | using IdentityServer4.AccessTokenValidation; |
| | | 7 | | using Microsoft.Extensions.DependencyInjection; |
| | | 8 | | using WinSolutions.Sveta.Server.Data.DataModel.Contexts; |
| | | 9 | | using WinSolutions.Sveta.Server.Data.DataModel.Entities; |
| | | 10 | | using Microsoft.Extensions.Configuration; |
| | | 11 | | using SVETA.Api.Data.DTO; |
| | | 12 | | using SVETA.Api.Data.Domain; |
| | | 13 | | using Microsoft.EntityFrameworkCore; |
| | | 14 | | |
| | | 15 | | namespace SVETA.Api.ConfigureOptions |
| | | 16 | | { |
| | | 17 | | public class ConfigureConfigurationsOptions : IConfigureOptions<ConfigurationsSettings> |
| | | 18 | | { |
| | | 19 | | private readonly IServiceScopeFactory _serviceScopeFactory; |
| | 3 | 20 | | public ConfigureConfigurationsOptions(IServiceScopeFactory serviceScopeFactory) |
| | 3 | 21 | | { |
| | 3 | 22 | | _serviceScopeFactory = serviceScopeFactory; |
| | 3 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// инициализируем и загружаем конфигурационные системные настройки из БД |
| | | 27 | | /// </summary> |
| | | 28 | | /// <param name="options">Объект ConfigurationsSettings, куда запишутся настройки из БД</param> |
| | | 29 | | public void Configure(ConfigurationsSettings options) |
| | 6 | 30 | | { |
| | 6 | 31 | | using (var scope = _serviceScopeFactory.CreateScope()) |
| | 6 | 32 | | { |
| | 6 | 33 | | var provider = scope.ServiceProvider; |
| | 6 | 34 | | using (var dbContext = provider.GetRequiredService<SvetaDbContext>()) |
| | 6 | 35 | | { |
| | 6 | 36 | | options.AppConfs = dbContext.sysConfigurations.Include(x => x.ValueType).Where(x => !x.IsDeleted).Se |
| | 6 | 37 | | } |
| | 6 | 38 | | } |
| | 6 | 39 | | } |
| | | 40 | | } |
| | | 41 | | } |