2021-04-02 17:28:07 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2022-04-11 18:00:34 +05:00
|
|
|
|
using AsbCloudApp.Data.SAUB;
|
2022-07-14 03:47:11 +05:00
|
|
|
|
using AsbCloudApp.Data.Subsystems;
|
2022-10-06 14:37:03 +05:00
|
|
|
|
using AsbCloudApp.Repositories;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
2022-08-03 16:35:21 +05:00
|
|
|
|
using AsbCloudApp.Services.Subsystems;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
using AsbCloudDb.Model;
|
2022-07-14 03:47:11 +05:00
|
|
|
|
using AsbCloudDb.Model.Subsystems;
|
2022-12-02 14:48:23 +05:00
|
|
|
|
using AsbCloudInfrastructure.Background;
|
2022-06-16 12:33:05 +05:00
|
|
|
|
using AsbCloudInfrastructure.Repository;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services;
|
2022-04-29 15:39:12 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.DailyReport;
|
2022-04-28 15:04:13 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.DetectOperations;
|
2022-04-11 18:00:34 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.DrillingProgram;
|
|
|
|
|
using AsbCloudInfrastructure.Services.SAUB;
|
2022-08-01 13:55:51 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.Subsystems;
|
2021-10-09 20:16:22 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.WellOperationService;
|
2022-01-10 16:00:09 +05:00
|
|
|
|
using AsbCloudInfrastructure.Validators;
|
2022-04-11 18:00:34 +05:00
|
|
|
|
using FluentValidation.AspNetCore;
|
2022-01-05 17:50:45 +05:00
|
|
|
|
using Mapster;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2022-11-17 16:09:51 +05:00
|
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2021-12-01 11:49:59 +05:00
|
|
|
|
using System;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure
|
|
|
|
|
{
|
|
|
|
|
public static class DependencyInjection
|
|
|
|
|
{
|
2021-12-02 11:11:14 +05:00
|
|
|
|
public static IAsbCloudDbContext MakeContext(string connectionString)
|
|
|
|
|
{
|
|
|
|
|
var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
|
|
|
|
.UseNpgsql(connectionString)
|
|
|
|
|
.Options;
|
|
|
|
|
var context = new AsbCloudDbContext(options);
|
|
|
|
|
return context;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-09 11:46:27 +05:00
|
|
|
|
public static void MapsterSetup()
|
2021-04-02 17:28:07 +05:00
|
|
|
|
{
|
2022-01-05 17:50:45 +05:00
|
|
|
|
TypeAdapterConfig.GlobalSettings.Default.Config
|
|
|
|
|
.ForType<DateTimeOffset, DateTime>()
|
|
|
|
|
.MapWith((source) => source.DateTime);
|
2022-01-12 13:33:16 +05:00
|
|
|
|
|
2022-01-05 17:50:45 +05:00
|
|
|
|
TypeAdapterConfig.GlobalSettings.Default.Config
|
|
|
|
|
.ForType<DateTime, DateTimeOffset>()
|
2022-01-09 11:46:27 +05:00
|
|
|
|
.MapWith((source) => source == default ? new DateTime(0, DateTimeKind.Utc) : source);
|
|
|
|
|
|
2022-05-31 12:30:03 +05:00
|
|
|
|
TypeAdapterConfig.GlobalSettings.Default.Config
|
|
|
|
|
.ForType<TimeDto, TimeOnly>()
|
|
|
|
|
.MapWith((source) => source == default ? default : source.MakeTimeOnly());
|
|
|
|
|
|
|
|
|
|
TypeAdapterConfig.GlobalSettings.Default.Config
|
|
|
|
|
.ForType<TimeOnly, TimeDto>()
|
|
|
|
|
.MapWith((source) => new(source));
|
2022-06-06 15:43:47 +05:00
|
|
|
|
|
|
|
|
|
TypeAdapterConfig.GlobalSettings.Default.Config
|
|
|
|
|
.ForType<TimeOnly, TimeDto>()
|
|
|
|
|
.MapWith((source) => new(source));
|
2022-06-06 17:00:53 +05:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
TypeAdapterConfig.GlobalSettings.Default.Config
|
|
|
|
|
.ForType<ClusterDto, Cluster>()
|
|
|
|
|
.Ignore(dst => dst.Deposit,
|
2022-06-15 14:57:37 +05:00
|
|
|
|
dst => dst.Wells);
|
2022-09-05 09:13:45 +05:00
|
|
|
|
|
|
|
|
|
TypeAdapterConfig.GlobalSettings.Default.Config
|
|
|
|
|
.ForType<FileCategoryDto, FileCategory>();
|
|
|
|
|
|
|
|
|
|
TypeAdapterConfig.GlobalSettings.Default.Config
|
2022-09-12 08:22:46 +05:00
|
|
|
|
.ForType<WellFinalDocumentDto, WellFinalDocument>();
|
2022-01-09 11:46:27 +05:00
|
|
|
|
}
|
2022-01-05 17:50:45 +05:00
|
|
|
|
|
2021-04-02 17:28:07 +05:00
|
|
|
|
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
|
|
|
|
|
{
|
2022-01-09 11:46:27 +05:00
|
|
|
|
MapsterSetup();
|
2022-09-28 14:51:47 +05:00
|
|
|
|
var connectionStringName = "DefaultConnection";
|
|
|
|
|
#if DEBUG
|
|
|
|
|
connectionStringName = "DebugConnection";
|
|
|
|
|
#endif
|
2021-04-02 17:28:07 +05:00
|
|
|
|
services.AddDbContext<AsbCloudDbContext>(options =>
|
2022-09-28 14:51:47 +05:00
|
|
|
|
options.UseNpgsql(configuration.GetConnectionString(connectionStringName)));
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
2022-11-17 17:54:25 +05:00
|
|
|
|
// TODO: переместить FluentValidation в описание моделей
|
|
|
|
|
services.AddFluentValidationClientsideAdapters();
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2022-11-17 16:09:51 +05:00
|
|
|
|
services.AddMemoryCache();
|
2021-04-02 17:28:07 +05:00
|
|
|
|
services.AddScoped<IAsbCloudDbContext>(provider => provider.GetService<AsbCloudDbContext>());
|
2022-02-28 14:44:26 +05:00
|
|
|
|
services.AddScoped<IEmailService, EmailService>();
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
2022-04-08 13:10:06 +05:00
|
|
|
|
services.AddSingleton(new WitsInfoService());
|
2022-04-11 17:22:52 +05:00
|
|
|
|
services.AddSingleton(new InstantDataRepository());
|
2022-11-15 17:44:48 +05:00
|
|
|
|
services.AddSingleton(provider=> TelemetryDataCache<TelemetryDataSaubDto>.GetInstance<TelemetryDataSaub>(configuration));
|
|
|
|
|
services.AddSingleton(provider=> TelemetryDataCache<TelemetryDataSpinDto>.GetInstance<TelemetryDataSpin>(configuration));
|
2021-05-12 16:03:14 +05:00
|
|
|
|
services.AddSingleton<ITelemetryTracker, TelemetryTracker>();
|
2022-02-08 13:03:56 +05:00
|
|
|
|
services.AddSingleton<IRequerstTrackerService, RequestTrackerService>();
|
2022-12-02 14:48:23 +05:00
|
|
|
|
services.AddSingleton<BackgroundWorker>();
|
2022-10-11 17:04:26 +05:00
|
|
|
|
services.AddSingleton<IReduceSamplingService>(provider => ReduceSamplingService.GetInstance(configuration));
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
|
|
|
|
services.AddTransient<IAuthService, AuthService>();
|
2021-07-19 15:31:50 +05:00
|
|
|
|
services.AddTransient<IClusterService, ClusterService>();
|
2022-12-07 08:47:41 +05:00
|
|
|
|
services.AddTransient<IProcessMapRepository, ProcessMapRepository>();
|
2021-12-03 09:44:10 +05:00
|
|
|
|
services.AddTransient<IDrillingProgramService, DrillingProgramService>();
|
2021-04-23 10:21:25 +05:00
|
|
|
|
services.AddTransient<IEventService, EventService>();
|
2022-10-06 14:37:03 +05:00
|
|
|
|
services.AddTransient<FileService>();
|
2021-12-03 09:44:10 +05:00
|
|
|
|
services.AddTransient<IMeasureService, MeasureService>();
|
|
|
|
|
services.AddTransient<IMessageService, MessageService>();
|
2022-04-11 18:00:34 +05:00
|
|
|
|
services.AddTransient<IOperationsStatService, OperationsStatService>();
|
2021-05-18 12:33:23 +05:00
|
|
|
|
services.AddTransient<IReportService, ReportService>();
|
2021-12-03 15:03:33 +05:00
|
|
|
|
services.AddTransient<ISetpointsService, SetpointsService>();
|
2021-12-03 09:44:10 +05:00
|
|
|
|
services.AddTransient<ITelemetryService, TelemetryService>();
|
|
|
|
|
services.AddTransient<ITelemetryUserService, TelemetryUserService>();
|
2022-01-05 17:50:45 +05:00
|
|
|
|
services.AddTransient<ITimezoneService, TimezoneService>();
|
2022-04-11 18:00:34 +05:00
|
|
|
|
services.AddTransient<IWellService, WellService>();
|
2021-12-03 09:44:10 +05:00
|
|
|
|
services.AddTransient<IWellOperationImportService, WellOperationImportService>();
|
2021-08-13 17:25:06 +05:00
|
|
|
|
services.AddTransient<IWellOperationService, WellOperationService>();
|
2022-03-17 16:56:13 +05:00
|
|
|
|
services.AddTransient<IScheduleReportService, ScheduleReportService>();
|
2022-04-26 16:45:52 +05:00
|
|
|
|
services.AddTransient<IDailyReportService, DailyReportService>();
|
2022-08-03 16:35:21 +05:00
|
|
|
|
services.AddTransient<IDetectedOperationService, DetectedOperationService>();
|
2022-08-05 17:10:56 +05:00
|
|
|
|
services.AddTransient<ISubsystemOperationTimeService, SubsystemOperationTimeService>();
|
2022-08-11 13:55:36 +05:00
|
|
|
|
services.AddTransient<IScheduleRepository, ScheduleRepository>();
|
|
|
|
|
services.AddTransient<IRepositoryWellRelated<OperationValueDto>, CrudWellRelatedServiceBase<OperationValueDto, OperationValue>>();
|
2022-07-27 18:14:07 +05:00
|
|
|
|
services.AddTransient<IUserSettingsRepository, UserSettingsRepository>();
|
2022-09-05 09:13:45 +05:00
|
|
|
|
services.AddTransient<IWellFinalDocumentsService, WellFinalDocumentsService>();
|
|
|
|
|
services.AddTransient<IFileCategoryService, FileCategoryService>();
|
2022-11-18 14:29:29 +05:00
|
|
|
|
services.AddTransient<ILimitingParameterService, LimitingParameterService>();
|
2021-08-24 10:59:10 +05:00
|
|
|
|
|
2021-09-10 11:28:57 +05:00
|
|
|
|
// admin crud services:
|
2022-12-01 15:56:11 +05:00
|
|
|
|
services.AddTransient<ICrudRepository<TelemetryDto>, CrudCacheRepositoryBase<TelemetryDto, Telemetry>>(s =>
|
|
|
|
|
new CrudCacheRepositoryBase<TelemetryDto, Telemetry>(
|
2022-06-06 15:43:47 +05:00
|
|
|
|
s.GetService<IAsbCloudDbContext>(),
|
2022-11-17 16:09:51 +05:00
|
|
|
|
s.GetService<IMemoryCache>(),
|
2022-06-06 15:43:47 +05:00
|
|
|
|
dbSet => dbSet.Include(t => t.Well))); // может быть включен в сервис TelemetryService
|
2022-12-05 12:44:46 +05:00
|
|
|
|
services.AddTransient<ICrudRepository<DepositDto>, CrudCacheRepositoryBase<DepositDto, Deposit>>(s =>
|
|
|
|
|
new CrudCacheRepositoryBase<DepositDto, Deposit>(
|
2022-06-06 15:43:47 +05:00
|
|
|
|
s.GetService<IAsbCloudDbContext>(),
|
2022-11-17 16:09:51 +05:00
|
|
|
|
s.GetService<IMemoryCache>(),
|
2022-06-06 15:43:47 +05:00
|
|
|
|
dbSet => dbSet.Include(d => d.Clusters)));
|
2022-12-01 15:56:11 +05:00
|
|
|
|
services.AddTransient<ICrudRepository<CompanyDto>, CrudCacheRepositoryBase<CompanyDto, Company>>(s =>
|
|
|
|
|
new CrudCacheRepositoryBase<CompanyDto, Company>(
|
2022-06-06 15:43:47 +05:00
|
|
|
|
s.GetService<IAsbCloudDbContext>(),
|
2022-11-17 16:09:51 +05:00
|
|
|
|
s.GetService<IMemoryCache>(),
|
2022-06-15 14:57:37 +05:00
|
|
|
|
dbSet => dbSet.Include(c => c.CompanyType)));
|
2022-08-05 17:10:56 +05:00
|
|
|
|
|
2022-12-01 15:56:11 +05:00
|
|
|
|
services.AddTransient<ICrudRepository<CompanyTypeDto>, CrudCacheRepositoryBase<CompanyTypeDto, CompanyType>>();
|
|
|
|
|
services.AddTransient<ICrudRepository<ClusterDto>, CrudCacheRepositoryBase<ClusterDto, Cluster>>(s =>
|
|
|
|
|
new CrudCacheRepositoryBase<ClusterDto, Cluster>(
|
2022-06-06 15:43:47 +05:00
|
|
|
|
s.GetService<IAsbCloudDbContext>(),
|
2022-11-17 16:09:51 +05:00
|
|
|
|
s.GetService<IMemoryCache>(),
|
2022-06-06 15:43:47 +05:00
|
|
|
|
dbSet => dbSet
|
|
|
|
|
.Include(c => c.Wells)
|
|
|
|
|
.Include(c => c.Deposit))); // может быть включен в сервис ClusterService
|
2022-10-19 15:31:53 +05:00
|
|
|
|
|
2022-12-01 15:56:11 +05:00
|
|
|
|
services.AddTransient<ICrudRepository<DrillerDto>, CrudCacheRepositoryBase<DrillerDto, Driller>>();
|
2022-10-19 15:31:53 +05:00
|
|
|
|
|
2022-09-30 13:34:50 +05:00
|
|
|
|
services.AddTransient<IFileRepository, FileRepository>();
|
2022-10-06 13:41:46 +05:00
|
|
|
|
services.AddTransient<IFileStorageRepository, FileStorageRepository>();
|
2022-10-19 13:56:34 +05:00
|
|
|
|
services.AddTransient<IWellCompositeRepository, WellCompositeRepository>();
|
2022-10-26 15:36:49 +05:00
|
|
|
|
services.AddTransient<IUserRoleRepository, UserRoleRepository>();
|
2022-10-27 11:22:39 +05:00
|
|
|
|
services.AddTransient<IUserRepository, UserRepository>();
|
2022-11-18 14:29:29 +05:00
|
|
|
|
services.AddTransient<ILimitingParameterRepository, LimitingParameterRepository>();
|
2022-07-14 03:47:11 +05:00
|
|
|
|
// Subsystem service
|
2022-12-01 15:56:11 +05:00
|
|
|
|
services.AddTransient<ICrudRepository<SubsystemDto>, CrudCacheRepositoryBase<SubsystemDto, Subsystem>>();
|
2022-08-15 15:08:17 +05:00
|
|
|
|
services.AddTransient<ISubsystemService, SubsystemService>();
|
2022-06-06 15:43:47 +05:00
|
|
|
|
|
2022-12-01 15:56:11 +05:00
|
|
|
|
services.AddTransient<ICrudRepository<PermissionDto>, CrudCacheRepositoryBase<PermissionDto, Permission>>();
|
2021-09-10 11:28:57 +05:00
|
|
|
|
|
2021-09-17 16:24:01 +05:00
|
|
|
|
// TelemetryData services
|
|
|
|
|
services.AddTransient<ITelemetryDataService<TelemetryDataSaubDto>, TelemetryDataSaubService>();
|
|
|
|
|
services.AddTransient<ITelemetryDataService<TelemetryDataSpinDto>, TelemetryDataSpinService>();
|
|
|
|
|
|
2022-04-08 13:10:06 +05:00
|
|
|
|
// 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>>();
|
|
|
|
|
|
2022-01-12 17:35:14 +05:00
|
|
|
|
services.AddValidators();
|
|
|
|
|
|
2021-04-02 17:28:07 +05:00
|
|
|
|
return services;
|
|
|
|
|
}
|
2021-12-01 11:49:59 +05:00
|
|
|
|
|
|
|
|
|
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.GetService<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)));
|
2021-12-02 11:11:14 +05:00
|
|
|
|
|
2021-04-02 17:28:07 +05:00
|
|
|
|
}
|
|
|
|
|
}
|