using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using PARR.DAL.CacheServices; using PARR.DAL.Configurations.DbSettings; using PARR.DAL.Context; using PARR.DAL.Contracts; using PARR.DAL.DomainServices.Implementations; using PARR.DAL.DomainServices.Interfaces; using PARR.DAL.DomainServices.Shortcodes; using PARR.DAL.InfluxDbServices; using PARR.DAL.Services.Implementation; using PARR.DAL.Services.Implementations; using PARR.DAL.Services.Implementations.Job; using PARR.DAL.Services.Implementations.Schedule; using PARR.DAL.Services.Implementations.Unit; using PARR.DAL.Services.Interfaces; using PARR.DAL.Services.Interfaces.Job; using PARR.DAL.Services.Interfaces.Schedule; using PARR.DAL.Services.Interfaces.Unit; using PARR.DAL.Settings; using PARR.DAL.TransformServices; namespace PARR.DAL { public static class ParrDalInstaller { /// /// Устанавливает Dal сервисы (1) /// /// /// public static void InstallDalServices(this IServiceCollection services, IConfiguration configuration) { //.EnableSensitiveDataLogging() - вкл подробное логирование при применении миграций, на проде выключить services.AddDbContext(opt => opt .EnableSensitiveDataLogging() .UseNpgsql(configuration.GetConnectionString("DefaultConnection")) ); #region Redis services.AddStackExchangeRedisCache(opt => { opt.Configuration = configuration.GetConnectionString("RedisConnection"); }); var groupedShortcodesCacheSettings = new GroupedShortcodesCacheSettings(); configuration.GetSection(nameof(GroupedShortcodesCacheSettings)).Bind(groupedShortcodesCacheSettings); services.AddSingleton(groupedShortcodesCacheSettings); services.AddTransient(); services.AddTransient(); #endregion #region InfluxDb var influxDbSettings = new InfluxDbSettings(); configuration.GetSection(nameof(InfluxDbSettings)).Bind(influxDbSettings); services.AddSingleton(influxDbSettings); services.AddTransient(); #endregion // Entity services services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); #region Schedule services.AddTransient(); services.AddTransient(); #endregion #region Unit services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); #endregion #region Job services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); #endregion // TransformServices services.AddTransient(); services.AddTransient(); #region DomainServces services.AddTransient(); services.AddTransient(); #endregion } /// /// Добавляет конфигурацию Dal (2) /// /// /// /// public static IConfigurationBuilder AddDalConfigurations(this IConfigurationBuilder builder, IServiceCollection services) { builder.Add(new DBConfigurationSource(services)); return builder; } /// /// Добавляет конфигурацию в сервисы (3) /// /// /// public static void AddDallSettings(this IServiceCollection services, IConfiguration configuration) { //SettingsFromDb configuration var settingsFromDb = new SettingsFromDb(); configuration.GetSection(nameof(SettingsFromDb)).Bind(settingsFromDb); services.AddSingleton(settingsFromDb); PrefixSettings.PrefixWithoutVariable = settingsFromDb.TemplatePrefixWithoutVariable; } } }