forked from ddrilling/AsbCloudServer
c8a5afa095
1. Удалены старые реализации сервисов 2. Поправлен WellInfoService 3. Поправлен csproj, добавлены ресурсы 4. Поправлена регистрация зависимостей
268 lines
16 KiB
C#
268 lines
16 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Data.SAUB;
|
|
using AsbCloudApp.Data.Subsystems;
|
|
using AsbCloudApp.Repositories;
|
|
using AsbCloudApp.Services;
|
|
using AsbCloudApp.Services.Subsystems;
|
|
using AsbCloudDb.Model;
|
|
using AsbCloudDb.Model.Subsystems;
|
|
using AsbCloudInfrastructure.Background;
|
|
using AsbCloudInfrastructure.Repository;
|
|
using AsbCloudInfrastructure.Services;
|
|
using AsbCloudInfrastructure.Services.DailyReport;
|
|
using AsbCloudInfrastructure.Services.DetectOperations;
|
|
using AsbCloudInfrastructure.Services.DrillingProgram;
|
|
using AsbCloudInfrastructure.Services.SAUB;
|
|
using AsbCloudInfrastructure.Services.Subsystems;
|
|
using AsbCloudInfrastructure.Services.Trajectory;
|
|
using AsbCloudInfrastructure.Services.WellOperationService;
|
|
using Mapster;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System;
|
|
using AsbCloudApp.Data.Manuals;
|
|
using AsbCloudApp.Data.ProcessMaps;
|
|
using AsbCloudApp.Services.AutoGeneratedDailyReports;
|
|
using AsbCloudApp.Services.Notifications;
|
|
using AsbCloudDb.Model.Manuals;
|
|
using AsbCloudInfrastructure.Services.AutoGeneratedDailyReports;
|
|
using AsbCloudApp.Services.WellOperationImport;
|
|
using AsbCloudInfrastructure.Services.WellOperationImport;
|
|
using AsbCloudApp.Data.WellOperationImport.Options;
|
|
using AsbCloudInfrastructure.Services.WellOperationImport.FileParser;
|
|
using AsbCloudApp.Services.ProcessMaps.WellDrillingProcessMap;
|
|
using AsbCloudApp.Services.ProcessMaps;
|
|
using AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap;
|
|
using AsbCloudInfrastructure.Services.ProcessMaps.WellDrillingProcessMap.Report;
|
|
|
|
namespace AsbCloudInfrastructure
|
|
{
|
|
|
|
public static class DependencyInjection
|
|
{
|
|
public static IAsbCloudDbContext MakeContext(string connectionString)
|
|
{
|
|
var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
|
.UseNpgsql(connectionString)
|
|
.Options;
|
|
var context = new AsbCloudDbContext(options);
|
|
return context;
|
|
}
|
|
|
|
public static void MapsterSetup()
|
|
{
|
|
TypeAdapterConfig.GlobalSettings.Default.Config
|
|
.ForType<DateTimeOffset, DateTime>()
|
|
.MapWith((source) => source.DateTime);
|
|
|
|
TypeAdapterConfig.GlobalSettings.Default.Config
|
|
.ForType<DateTime, DateTimeOffset>()
|
|
.MapWith((source) => source == default ? new DateTime(0, DateTimeKind.Utc) : source);
|
|
|
|
TypeAdapterConfig.GlobalSettings.Default.Config
|
|
.ForType<TimeDto, TimeOnly>()
|
|
.MapWith((source) => source.MakeTimeOnly());
|
|
|
|
TypeAdapterConfig.GlobalSettings.Default.Config
|
|
.ForType<TimeOnly, TimeDto>()
|
|
.MapWith((source) => new(source));
|
|
|
|
TypeAdapterConfig.GlobalSettings.Default.Config
|
|
.ForType<TimeOnly, TimeDto>()
|
|
.MapWith((source) => new(source));
|
|
|
|
#pragma warning disable CS8603 // Possible null reference return.
|
|
TypeAdapterConfig.GlobalSettings.Default.Config
|
|
.ForType<WellDto, Well>()
|
|
.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<ClusterDto, Cluster>()
|
|
.Ignore(dst => dst.Deposit,
|
|
dst => dst.Wells);
|
|
|
|
TypeAdapterConfig.GlobalSettings.Default.Config
|
|
.ForType<FileCategoryDto, FileCategory>();
|
|
|
|
TypeAdapterConfig.GlobalSettings.Default.Config
|
|
.ForType<WellFinalDocumentDto, WellFinalDocument>();
|
|
|
|
TypeAdapterConfig.GlobalSettings.Default.Config
|
|
.ForType<NotificationDto, Notification>()
|
|
.Ignore(dst => dst.NotificationCategory,
|
|
dst => dst.User);
|
|
}
|
|
|
|
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
MapsterSetup();
|
|
var connectionStringName = "DefaultConnection";
|
|
#if DEBUG
|
|
connectionStringName = "DebugConnection";
|
|
#endif
|
|
services.AddDbContext<AsbCloudDbContext>(options =>
|
|
options.UseNpgsql(configuration.GetConnectionString(connectionStringName)));
|
|
|
|
|
|
services.AddMemoryCache();
|
|
services.AddScoped<IAsbCloudDbContext>(provider => provider.GetRequiredService<AsbCloudDbContext>());
|
|
|
|
services.AddSingleton(new WitsInfoService());
|
|
services.AddSingleton(provider => TelemetryDataCache<TelemetryDataSaubDto>.GetInstance<TelemetryDataSaub>(provider));
|
|
services.AddSingleton(provider => TelemetryDataCache<TelemetryDataSpinDto>.GetInstance<TelemetryDataSpin>(provider));
|
|
services.AddSingleton<IRequerstTrackerService, RequestTrackerService>();
|
|
services.AddSingleton<BackgroundWorker>();
|
|
services.AddSingleton<NotificationBackgroundWorker>();
|
|
services.AddSingleton<IReduceSamplingService>(provider => ReduceSamplingService.GetInstance(configuration));
|
|
|
|
services.AddTransient<IAuthService, AuthService>();
|
|
services.AddTransient<IWellDrillingProcessMapRepository, WellDrillingProcessMapRepository>();
|
|
services.AddTransient<IWellReamProcessMapRepository, WellReamProcessMapRepository>();
|
|
services.AddTransient<IDepositRepository, DepositRepository>();
|
|
services.AddTransient<IDrillingProgramService, DrillingProgramService>();
|
|
services.AddTransient<IEventService, EventService>();
|
|
services.AddTransient<FileService>();
|
|
services.AddTransient<IMeasureService, MeasureService>();
|
|
services.AddTransient<IMessageService, MessageService>();
|
|
services.AddTransient<IOperationsStatService, OperationsStatService>();
|
|
services.AddTransient<IReportService, ReportService>();
|
|
services.AddTransient<ISetpointsService, SetpointsService>();
|
|
services.AddTransient<ITelemetryService, TelemetryService>();
|
|
services.AddTransient<ITelemetryUserService, TelemetryUserService>();
|
|
services.AddTransient<ITimezoneService, TimezoneService>();
|
|
services.AddTransient<IWellService, WellService>();
|
|
services.AddTransient<IWellOperationImportService, WellOperationImportService>();
|
|
services.AddTransient<IProcessMapReportExportService, WellDrillingProcessMapReportExportService>();
|
|
services.AddTransient<IPlannedTrajectoryImportService, PlannedTrajectoryImportService>();
|
|
services.AddTransient<IWellOperationRepository, WellOperationRepository>();
|
|
services.AddTransient<IScheduleReportService, ScheduleReportService>();
|
|
services.AddTransient<IDailyReportService, DailyReportService>();
|
|
services.AddTransient<IDetectedOperationService, DetectedOperationService>();
|
|
services.AddTransient<ISubsystemOperationTimeService, SubsystemOperationTimeService>();
|
|
services.AddTransient<IScheduleRepository, ScheduleRepository>();
|
|
services.AddTransient<IRepositoryWellRelated<OperationValueDto>, CrudWellRelatedRepositoryBase<OperationValueDto, OperationValue>>();
|
|
services.AddTransient<IUserSettingsRepository, UserSettingsRepository>();
|
|
services.AddTransient<IWellFinalDocumentsService, WellFinalDocumentsService>();
|
|
services.AddTransient<IFileCategoryService, FileCategoryService>();
|
|
services.AddTransient<ILimitingParameterService, LimitingParameterService>();
|
|
services.AddTransient<IWellDrillingProcessMapReportService, WellDrillingProcessMapReportService>();
|
|
services.AddTransient<IProcessMapImportService, WellDrillingProcessMapImportService>();
|
|
services.AddTransient<WellInfoService>();
|
|
services.AddTransient<IHelpPageService, HelpPageService>();
|
|
|
|
services.AddTransient<TrajectoryService>();
|
|
|
|
services.AddTransient<IGtrRepository, GtrWitsRepository>();
|
|
|
|
services.AddTransient<NotificationService>();
|
|
services.AddTransient<INotificationRepository, NotificationRepository>();
|
|
services.AddTransient<ICrudRepository<NotificationCategoryDto>, CrudCacheRepositoryBase<NotificationCategoryDto,
|
|
NotificationCategory>>();
|
|
|
|
// admin crud services:
|
|
services.AddTransient<ICrudRepository<TelemetryDto>, CrudCacheRepositoryBase<TelemetryDto, Telemetry>>(s =>
|
|
new CrudCacheRepositoryBase<TelemetryDto, Telemetry>(
|
|
s.GetRequiredService<IAsbCloudDbContext>(),
|
|
s.GetRequiredService<IMemoryCache>(),
|
|
dbSet => dbSet.Include(t => t.Well))); // может быть включен в сервис TelemetryService
|
|
services.AddTransient<ICrudRepository<DepositDto>, CrudCacheRepositoryBase<DepositDto, Deposit>>(s =>
|
|
new CrudCacheRepositoryBase<DepositDto, Deposit>(
|
|
s.GetRequiredService<IAsbCloudDbContext>(),
|
|
s.GetRequiredService<IMemoryCache>(),
|
|
dbSet => dbSet.Include(d => d.Clusters)));
|
|
services.AddTransient<ICrudRepository<CompanyDto>, CrudCacheRepositoryBase<CompanyDto, Company>>(s =>
|
|
new CrudCacheRepositoryBase<CompanyDto, Company>(
|
|
s.GetRequiredService<IAsbCloudDbContext>(),
|
|
s.GetRequiredService<IMemoryCache>(),
|
|
dbSet => dbSet.Include(c => c.CompanyType)));
|
|
|
|
services.AddTransient<ICrudRepository<CompanyTypeDto>, CrudCacheRepositoryBase<CompanyTypeDto, CompanyType>>();
|
|
services.AddTransient<ICrudRepository<ClusterDto>, CrudCacheRepositoryBase<ClusterDto, Cluster>>(s =>
|
|
new CrudCacheRepositoryBase<ClusterDto, Cluster>(
|
|
s.GetRequiredService<IAsbCloudDbContext>(),
|
|
s.GetRequiredService<IMemoryCache>(),
|
|
dbSet => dbSet
|
|
.Include(c => c.Wells)
|
|
.Include(c => c.Deposit))); // может быть включен в сервис ClusterService
|
|
|
|
services.AddTransient<ICrudRepository<DrillerDto>, CrudCacheRepositoryBase<DrillerDto, Driller>>();
|
|
|
|
services.AddTransient<IHelpPageRepository, HelpPageRepository>();
|
|
services.AddTransient<IFileRepository, FileRepository>();
|
|
services.AddTransient<IFileStorageRepository, FileStorageRepository>();
|
|
services.AddTransient<IWellCompositeRepository, WellCompositeRepository>();
|
|
services.AddTransient<IUserRoleRepository, UserRoleRepository>();
|
|
services.AddTransient<IUserRepository, UserRepository>();
|
|
services.AddTransient<ILimitingParameterRepository, LimitingParameterRepository>();
|
|
services.AddTransient<ITelemetryWirelineRunOutRepository, TelemetryWirelineRunOutRepository>();
|
|
services.AddTransient<IWellFinalDocumentsRepository, WellFinalDocumentsRepository>();
|
|
services.AddTransient<ITrajectoryPlanRepository, TrajectoryPlanRepository>();
|
|
services.AddTransient<ITrajectoryFactRepository, TrajectoryFactRepository>();
|
|
services.AddTransient<IFaqRepository, FaqRepository>();
|
|
services.AddTransient<ISlipsStatService, SlipsStatService>();
|
|
services.AddTransient<IWellContactService, WellContactService>();
|
|
services.AddTransient<ICrudRepository<WellSectionTypeDto>, CrudCacheRepositoryBase<WellSectionTypeDto,
|
|
WellSectionType>>();
|
|
|
|
// Subsystem service
|
|
services.AddTransient<ICrudRepository<SubsystemDto>, CrudCacheRepositoryBase<SubsystemDto, Subsystem>>();
|
|
services.AddTransient<ISubsystemService, SubsystemService>();
|
|
|
|
services.AddTransient<ICrudRepository<PermissionDto>, CrudCacheRepositoryBase<PermissionDto, Permission>>();
|
|
|
|
// TelemetryData services
|
|
services.AddTransient<ITelemetryDataSaubService, TelemetryDataSaubService>();
|
|
services.AddTransient<ITelemetryDataService<TelemetryDataSpinDto>, TelemetryDataSpinService>();
|
|
|
|
// Wits
|
|
services.AddTransient<IWitsRecordRepository<AsbCloudApp.Data.WITS.Record1Dto>, WitsRecordRepository<AsbCloudApp.Data.WITS.Record1Dto, AsbCloudDb.Model.WITS.Record1>>();
|
|
services.AddTransient<IWitsRecordRepository<AsbCloudApp.Data.WITS.Record7Dto>, WitsRecordRepository<AsbCloudApp.Data.WITS.Record7Dto, AsbCloudDb.Model.WITS.Record7>>();
|
|
services.AddTransient<IWitsRecordRepository<AsbCloudApp.Data.WITS.Record8Dto>, WitsRecordRepository<AsbCloudApp.Data.WITS.Record8Dto, AsbCloudDb.Model.WITS.Record8>>();
|
|
services.AddTransient<IWitsRecordRepository<AsbCloudApp.Data.WITS.Record50Dto>, WitsRecordRepository<AsbCloudApp.Data.WITS.Record50Dto, AsbCloudDb.Model.WITS.Record50>>();
|
|
services.AddTransient<IWitsRecordRepository<AsbCloudApp.Data.WITS.Record60Dto>, WitsRecordRepository<AsbCloudApp.Data.WITS.Record60Dto, AsbCloudDb.Model.WITS.Record60>>();
|
|
services.AddTransient<IWitsRecordRepository<AsbCloudApp.Data.WITS.Record61Dto>, WitsRecordRepository<AsbCloudApp.Data.WITS.Record61Dto, AsbCloudDb.Model.WITS.Record61>>();
|
|
|
|
services.AddTransient<IAutoGeneratedDailyReportService, AutoGeneratedDailyReportService>();
|
|
services.AddTransient<IAutoGeneratedDailyReportMakerService, AutoGeneratedDailyReportMakerService>();
|
|
|
|
services.AddTransient<IManualDirectoryRepository, ManualDirectoryRepository>();
|
|
services.AddTransient<IManualCatalogService, ManualCatalogService>();
|
|
services.AddTransient<ICrudRepository<ManualDto>, CrudRepositoryBase<ManualDto, Manual>>();
|
|
|
|
services.AddTransient<IWellboreService, WellboreService>();
|
|
|
|
services.AddTransient<IWellOperationExportService, WellOperationExportService>();
|
|
services.AddTransient<IWellOperationImportService, WellOperationImportService>();
|
|
services.AddTransient<IWellOperationImportTemplateService, WellOperationImportTemplateService>();
|
|
|
|
services.AddTransient<IWellOperationExcelParser<WellOperationImportDefaultOptionsDto>, WellOperationDefaultExcelParser>();
|
|
services.AddTransient<IWellOperationExcelParser<WellOperationImportGazpromKhantosOptionsDto>, WellOperationGazpromKhantosExcelParser>();
|
|
|
|
return services;
|
|
}
|
|
|
|
public static IServiceCollection AddTransientLazy<TService, TImplementation>(this IServiceCollection services)
|
|
where TService : class
|
|
where TImplementation : class, TService
|
|
=> services.AddTransient<TService, TImplementation>()
|
|
.AddTransient(provider => new Lazy<TService>(provider.GetRequiredService<TService>));
|
|
|
|
public static IServiceCollection AddTransientLazy<TService, TImplementation>(this IServiceCollection services, Func<IServiceProvider, TImplementation> implementationFactory)
|
|
where TService : class
|
|
where TImplementation : class, TService
|
|
=> services.AddTransient<TService, TImplementation>(implementationFactory)
|
|
.AddTransient(provider => new Lazy<TService>(() => implementationFactory(provider)));
|
|
|
|
}
|
|
|
|
}
|