using System; using AsbCloudApp.Data; using AsbCloudApp.Data.DrillTestReport; using AsbCloudApp.Data.Manuals; using AsbCloudApp.Data.ProcessMaps; using AsbCloudApp.Data.SAUB; using AsbCloudApp.Data.Subsystems; using AsbCloudApp.Data.Trajectory; using AsbCloudApp.Data.WellOperationImport.Options; using AsbCloudApp.Repositories; using AsbCloudApp.Services; using AsbCloudApp.Services.Notifications; using AsbCloudApp.Services.ProcessMaps; using AsbCloudApp.Services.ProcessMaps.WellDrilling; using AsbCloudApp.Services.WellOperationImport; using AsbCloudDb.Model; using AsbCloudDb.Model.Manuals; using AsbCloudDb.Model.ProcessMaps; using AsbCloudDb.Model.Trajectory; 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.ProcessMaps.Report; using AsbCloudInfrastructure.Services.ProcessMaps.WellDrilling; using AsbCloudInfrastructure.Services.SAUB; using AsbCloudInfrastructure.Services.Subsystems; using AsbCloudInfrastructure.Services.Trajectory; using AsbCloudInfrastructure.Services.Trajectory.Export; using AsbCloudInfrastructure.Services.Trajectory.Import; using AsbCloudInfrastructure.Services.WellOperationImport; using AsbCloudInfrastructure.Services.WellOperationImport.FileParser; using AsbCloudInfrastructure.Services.WellOperationService; using Mapster; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using AsbCloudApp.Data.DailyReport.Blocks.TimeBalance; using AsbCloudApp.Services.DailyReport; using AsbCloudDb.Model.DailyReports.Blocks.TimeBalance; using AsbCloudDb.Model.WellSections; using AsbCloudInfrastructure.Services.ProcessMaps; namespace AsbCloudInfrastructure { public static class DependencyInjection { public static void MapsterSetup() { 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.AxialLoad, src => new PlanLimitDto { LimitMax = src.AxialLoadLimitMax, Plan = src.AxialLoadPlan }) .Map(dest => dest.Flow, src => new PlanLimitDto { LimitMax = src.FlowLimitMax, Plan = src.FlowPlan }) .Map(dest => dest.Pressure, src => new PlanLimitDto { LimitMax = src.PressureLimitMax, Plan = src.PressurePlan }) .Map(dest => dest.TopDriveSpeed, src => new PlanLimitDto { LimitMax = src.TopDriveSpeedLimitMax, Plan = src.TopDriveSpeedPlan }) .Map(dest => dest.TopDriveTorque, src => new PlanLimitDto { LimitMax = src.TopDriveTorqueLimitMax, Plan = src.TopDriveTorquePlan }); TypeAdapterConfig.GlobalSettings.Default.Config .ForType() .Map(dest => dest.AxialLoadPlan, src => src.AxialLoad.Plan) .Map(dest => dest.AxialLoadLimitMax, src => src.AxialLoad.LimitMax) .Map(dest => dest.FlowPlan, src => src.Flow.Plan) .Map(dest => dest.FlowLimitMax, src => src.Flow.LimitMax) .Map(dest => dest.PressurePlan, src => src.Pressure.Plan) .Map(dest => dest.PressureLimitMax, src => src.Pressure.LimitMax) .Map(dest => dest.TopDriveSpeedPlan, src => src.TopDriveSpeed.Plan) .Map(dest => dest.TopDriveSpeedLimitMax, src => src.TopDriveSpeed.LimitMax) .Map(dest => dest.TopDriveTorquePlan, src => src.TopDriveTorque.Plan) .Map(dest => dest.TopDriveTorqueLimitMax, src => src.TopDriveTorque.LimitMax); 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 }); } 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, ProcessMapPlanRepository>(); services.AddTransient, ProcessMapPlanRepository>(); 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, 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, CrudCacheRepositoryBase>(); 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, TrajectoryEditableRepository>(); services.AddTransient, TrajectoryEditableRepository>(); services.AddTransient(); 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, WellOperationDefaultExcelParser>(); services.AddTransient, WellOperationGazpromKhantosExcelParser>(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient, CrudWellRelatedRepositoryBase>(); services.AddTransient, ProcessMapPlanService>(); services.AddTransient, ProcessMapPlanService>(); services.AddTransient(); return services; } } }