using AsbCloudApp.Data; using AsbCloudApp.Data.DailyReport.Blocks.TimeBalance; using AsbCloudApp.Data.DetectedOperation; using AsbCloudApp.Data.DrillTestReport; using AsbCloudApp.Data.Manuals; using AsbCloudApp.Data.ProcessMaps; using AsbCloudApp.Data.ProcessMaps.Functions; using AsbCloudApp.Data.ProcessMaps.Operations; using AsbCloudApp.Data.SAUB; using AsbCloudApp.Data.Subsystems; using AsbCloudApp.Data.Trajectory; using AsbCloudApp.Repositories; using AsbCloudApp.Requests; using AsbCloudApp.Services; using AsbCloudApp.Services.DailyReport; using AsbCloudApp.Services.Notifications; using AsbCloudApp.Services.ProcessMaps.WellDrilling; using AsbCloudDb.Model; using AsbCloudDb.Model.DailyReports.Blocks.TimeBalance; using AsbCloudDb.Model.Manuals; using AsbCloudDb.Model.ProcessMapPlan; using AsbCloudDb.Model.ProcessMapPlan.Functions; using AsbCloudDb.Model.ProcessMapPlan.Operations; using AsbCloudDb.Model.Trajectory; using AsbCloudDb.Model.WellSections; using AsbCloudInfrastructure.Background; using AsbCloudInfrastructure.Repository; using AsbCloudInfrastructure.Services; using AsbCloudInfrastructure.Services.DailyReport; using AsbCloudInfrastructure.Services.DetectOperations; using AsbCloudInfrastructure.Services.DrillingProgram; using AsbCloudInfrastructure.Services.DrillTestReport; using AsbCloudInfrastructure.Services.ProcessMapPlan.Export; using AsbCloudInfrastructure.Services.ProcessMapPlan.Parser; using AsbCloudInfrastructure.Services.ProcessMaps.Report; using AsbCloudInfrastructure.Services.SAUB; using AsbCloudInfrastructure.Services.Subsystems; using AsbCloudInfrastructure.Services.Trajectory; using AsbCloudInfrastructure.Services.Trajectory.Export; using AsbCloudInfrastructure.Services.Trajectory.Parser; using AsbCloudInfrastructure.Services.WellOperations.Factories; using AsbCloudInfrastructure.Services.WellOperationService; using AsbCloudInfrastructure.Services.WellOperationService.WellOperationService; using Mapster; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System; using AsbCloudApp.Services.WellReport; using AsbCloudInfrastructure.Services.WellReport; namespace AsbCloudInfrastructure; public static class DependencyInjection { public static void MapsterSetup() { TypeAdapterConfig.GlobalSettings.Default.Config .ForType() .Ignore(source => source.Author) .Ignore(source => source.Well); TypeAdapterConfig.GlobalSettings.Default.Config .ForType() .Ignore(source => source.OperationCategory); TypeAdapterConfig.GlobalSettings.Default.Config .ForType() .Ignore(source => source.Driller); #pragma warning disable CS8603 // Possible null reference return. TypeAdapterConfig.GlobalSettings.Default.Config .ForType() .Ignore(dst => dst.Author, dst => dst.Editor); #pragma warning restore CS8603 // Possible null reference return. TypeAdapterConfig.GlobalSettings.Default.Config .ForType() .MapWith((source) => source.DateTime); TypeAdapterConfig.GlobalSettings.Default.Config .ForType() .MapWith((source) => source == default ? new DateTime(0, DateTimeKind.Utc) : source); TypeAdapterConfig.GlobalSettings.Default.Config .ForType() .MapWith((source) => source.MakeTimeOnly()); TypeAdapterConfig.GlobalSettings.Default.Config .ForType() .MapWith((source) => new(source)); TypeAdapterConfig.GlobalSettings.Default.Config .ForType() .MapWith((source) => new(source)); #pragma warning disable CS8603 // Possible null reference return. TypeAdapterConfig.GlobalSettings.Default.Config .ForType() .Ignore(dst => dst.Cluster, dst => dst.RelationCompaniesWells, dst => dst.Telemetry, dst => dst.WellComposites, dst => dst.WellCompositeSrcs, dst => dst.WellOperations, dst => dst.WellType); #pragma warning restore CS8603 // Possible null reference return. TypeAdapterConfig.GlobalSettings.Default.Config .ForType() .Ignore(dst => dst.Deposit, dst => dst.Wells); TypeAdapterConfig.GlobalSettings.Default.Config .ForType(); TypeAdapterConfig.GlobalSettings.Default.Config .ForType(); TypeAdapterConfig.GlobalSettings.Default.Config .ForType() .Ignore(dst => dst.NotificationCategory, dst => dst.User); TypeAdapterConfig.GlobalSettings.Default.Config .ForType() .Map(dest => dest.DurationHours, src => new PlanFactDto() { Plan = src.DurationHoursPlan, Fact = src.DurationHoursFact }); TypeAdapterConfig.GlobalSettings.Default.Config .ForType() .Map(dest => dest.WellDepth, src => new PlanFactDto() { Plan = src.WellDepthPlan }); TypeAdapterConfig>.NewConfig() .Include>() .Map(dest => dest, src => new ChangeLogDto() { Item = src.Adapt() }); TypeAdapterConfig>.NewConfig() .Include>() .Map(dest => dest, src => new ChangeLogDto() { Item = src.Adapt() }); TypeAdapterConfig>.NewConfig() .Include>() .Map(dest => dest, src => new ChangeLogDto() { Item = src.Adapt() }); TypeAdapterConfig>.NewConfig() .Include>() .Map(dest => dest, src => new ChangeLogDto() { Item = src.Adapt() }); TypeAdapterConfig>.NewConfig() .Include>() .Map(dest => dest, src => new ChangeLogDto() { Item = src.Adapt() }); TypeAdapterConfig>.NewConfig() .Include>() .Map(dest => dest, src => new ChangeLogDto() { Item = src.Adapt() }); TypeAdapterConfig>.NewConfig() .Include>() .Map(dest => dest, src => new ChangeLogDto() { Item = src.Adapt() }); TypeAdapterConfig>.NewConfig() .Include>() .Map(dest => dest, src => new ChangeLogDto() { Item = src.Adapt() }); TypeAdapterConfig>.NewConfig() .Include>() .Map(dest => dest, src => new ChangeLogDto() { Item = src.Adapt() }); TypeAdapterConfig>.NewConfig() .Include>() .Map(dest => dest, src => new ChangeLogDto() { Item = src.Adapt() }); TypeAdapterConfig>.NewConfig() .Include>() .Map(dest => dest, src => new ChangeLogDto() { Item = src.Adapt() }); TypeAdapterConfig>.NewConfig() .Include>() .Map(dest => dest, src => new ChangeLogDto() { Item = src.Adapt() }); TypeAdapterConfig>.NewConfig() .Include>() .Map(dest => dest, src => new ChangeLogDto() { Item = src.Adapt() }); TypeAdapterConfig>.NewConfig() .Include>() .Map(dest => dest, src => new ChangeLogDto() { Item = src.Adapt() }); TypeAdapterConfig>.NewConfig() .Include>() .Map(dest => dest, src => new ChangeLogDto() { Item = src.Adapt() }); TypeAdapterConfig>.NewConfig() .Include>() .Map(dest => dest, src => new ChangeLogDto() { Item = src.Adapt() }); TypeAdapterConfig>.NewConfig() .Include>() .Map(dest => dest, src => new ChangeLogDto() { Item = src.Adapt() }); TypeAdapterConfig>.NewConfig() .Include>() .Map(dest => dest, src => new ChangeLogDto() { Item = src.Adapt() }); } public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration) { MapsterSetup(); string connectionStringName = "DefaultConnection"; #if DEBUG connectionStringName = "DebugConnection"; #endif services.AddDbContext(options => options.UseNpgsql(configuration.GetConnectionString(connectionStringName))); services.AddMemoryCache(); services.AddScoped(provider => provider.GetRequiredService()); services.AddSingleton(new WitsInfoService()); services.AddSingleton>(provider => TelemetryDataCache.GetInstance(provider)); services.AddSingleton>(provider => TelemetryDataCache.GetInstance(provider)); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(provider => ReduceSamplingService.GetInstance(configuration)); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddScoped(); services.AddTransient(); services.AddTransient(); services.AddScoped(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient, CrudWellRelatedRepositoryBase>(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient< IChangeLogRepository, ProcessMapPlanBaseRepository>(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient, CrudCacheRepositoryBase>(); services.AddTransient(); services.AddTransient(); // admin crud services: services.AddTransient, CrudCacheRepositoryBase>(s => new CrudCacheRepositoryBase( s.GetRequiredService(), s.GetRequiredService(), dbSet => dbSet.Include(t => t.Well))); // может быть включен в сервис TelemetryService services.AddTransient, CrudCacheRepositoryBase>(s => new CrudCacheRepositoryBase( s.GetRequiredService(), s.GetRequiredService(), dbSet => dbSet.Include(d => d.Clusters) .ThenInclude(c => c.Wells))); services.AddTransient, CrudCacheRepositoryBase>(s => new CrudCacheRepositoryBase( s.GetRequiredService(), s.GetRequiredService(), dbSet => dbSet.Include(c => c.CompanyType))); services.AddTransient, CrudCacheRepositoryBase>(); services.AddTransient, CrudCacheRepositoryBase>(s => new CrudCacheRepositoryBase( s.GetRequiredService(), s.GetRequiredService(), dbSet => dbSet .Include(c => c.Wells) .Include(c => c.Deposit))); // может быть включен в сервис ClusterService services.AddTransient, CrudCacheRepositoryBase>(); 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, TrajectoryEditableRepository>(); services.AddTransient, TrajectoryEditableRepository>(); services.AddTransient(); services.AddTransient, TrajectoryEditableRepository>(); services.AddTransient, TrajectoryEditableRepository>(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient, CrudCacheRepositoryBase>(); services.AddTransient, CrudCacheRepositoryBase>(); services.AddTransient, CrudCacheRepositoryBase>(); // TelemetryData services services.AddTransient(); services.AddTransient, TelemetryDataSpinService>(); // Wits services.AddTransient, WitsRecordRepository>(); services.AddTransient, WitsRecordRepository>(); services.AddTransient, WitsRecordRepository>(); services.AddTransient, WitsRecordRepository>(); services.AddTransient, WitsRecordRepository>(); services.AddTransient, WitsRecordRepository>(); services.AddTransient(); services.AddTransient, DrillTestReportMakerService>(); services.AddTransient(); services.AddTransient(); services.AddTransient, CrudRepositoryBase>(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient, CrudWellRelatedRepositoryBase>(); 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(); 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(); return services; } }