2021-04-02 17:28:07 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2022-04-11 18:00:34 +05:00
|
|
|
|
using AsbCloudApp.Data.SAUB;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using AsbCloudInfrastructure.Services;
|
2021-04-07 18:01:56 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.Cache;
|
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;
|
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;
|
|
|
|
|
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,
|
|
|
|
|
dst=>dst.Wells);
|
|
|
|
|
|
|
|
|
|
|
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();
|
2021-04-02 17:28:07 +05:00
|
|
|
|
services.AddDbContext<AsbCloudDbContext>(options =>
|
2021-12-07 18:27:52 +05:00
|
|
|
|
options.UseNpgsql(configuration.GetConnectionString("DefaultConnection")));
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
2021-12-27 17:35:49 +05:00
|
|
|
|
services.AddFluentValidation();
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-04-02 17:28:07 +05:00
|
|
|
|
services.AddScoped<IAsbCloudDbContext>(provider => provider.GetService<AsbCloudDbContext>());
|
2021-11-10 14:23:53 +05:00
|
|
|
|
services.AddScoped<IFileShareService, GoogleDriveService>();
|
2022-02-28 14:44:26 +05:00
|
|
|
|
services.AddScoped<IEmailService, EmailService>();
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
2022-04-28 15:04:13 +05:00
|
|
|
|
services.AddHostedService<OperationDetectionBackgroundService>();
|
2021-05-19 14:41:27 +05:00
|
|
|
|
|
2022-04-08 13:10:06 +05:00
|
|
|
|
services.AddSingleton(new WitsInfoService());
|
2021-04-07 18:01:56 +05:00
|
|
|
|
services.AddSingleton(new CacheDb());
|
2022-04-11 17:22:52 +05:00
|
|
|
|
services.AddSingleton(new InstantDataRepository());
|
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-02-17 15:37:27 +05:00
|
|
|
|
services.AddSingleton<IBackgroundWorkerService, BackgroundWorkerService>();
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
|
|
|
|
services.AddTransient<IAuthService, AuthService>();
|
2021-07-19 15:31:50 +05:00
|
|
|
|
services.AddTransient<IClusterService, ClusterService>();
|
2021-12-03 09:44:10 +05:00
|
|
|
|
services.AddTransient<IDrillFlowChartService, DrillFlowChartService>();
|
|
|
|
|
services.AddTransient<IDrillingProgramService, DrillingProgramService>();
|
2021-12-03 15:03:33 +05:00
|
|
|
|
services.AddTransient<IDrillParamsService, DrillParamsService>();
|
2021-04-23 10:21:25 +05:00
|
|
|
|
services.AddTransient<IEventService, EventService>();
|
2021-12-03 09:44:10 +05:00
|
|
|
|
services.AddTransient<IFileService, FileService>();
|
|
|
|
|
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>();
|
2021-12-11 16:46:04 +05:00
|
|
|
|
services.AddTransient<IUserService, UserService>();
|
2021-12-03 15:03:33 +05:00
|
|
|
|
services.AddTransient<IUserRoleService, UserRoleService>();
|
2022-04-11 18:00:34 +05:00
|
|
|
|
services.AddTransient<IWellService, WellService>();
|
2021-12-03 09:44:10 +05:00
|
|
|
|
services.AddTransient<IWellCompositeService, WellCompositeService>();
|
|
|
|
|
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-04-28 15:04:13 +05:00
|
|
|
|
services.AddTransient<IDetectedOperationService, DetectedOperationService>();
|
2022-05-22 21:18:43 +05:00
|
|
|
|
services.AddTransient<IDrillerService, DrillerService>();
|
|
|
|
|
services.AddTransient<IScheduleService, ScheduleService>();
|
2022-06-08 14:37:05 +05:00
|
|
|
|
services.AddTransient<IOperationValueService, OperationValueService>();
|
2021-08-24 10:59:10 +05:00
|
|
|
|
|
2021-09-10 11:28:57 +05:00
|
|
|
|
// admin crud services:
|
2022-06-06 15:43:47 +05:00
|
|
|
|
services.AddTransient<ICrudService<TelemetryDto>, CrudServiceBase<TelemetryDto, Telemetry>>(s =>
|
|
|
|
|
new CrudCacheServiceBase<TelemetryDto, Telemetry>(
|
|
|
|
|
s.GetService<IAsbCloudDbContext>(),
|
|
|
|
|
dbSet => dbSet.Include(t => t.Well))); // может быть включен в сервис TelemetryService
|
2021-12-03 15:03:33 +05:00
|
|
|
|
services.AddTransient<ICrudService<DrillParamsDto>, DrillParamsService>();
|
2022-06-06 15:43:47 +05:00
|
|
|
|
services.AddTransient<ICrudService<DepositDto>, CrudCacheServiceBase<DepositDto, Deposit>>(s =>
|
|
|
|
|
new CrudCacheServiceBase<DepositDto, Deposit>(
|
|
|
|
|
s.GetService<IAsbCloudDbContext>(),
|
|
|
|
|
dbSet => dbSet.Include(d => d.Clusters)));
|
|
|
|
|
services.AddTransient<ICrudService<CompanyDto>, CrudCacheServiceBase<CompanyDto, Company>>(s =>
|
|
|
|
|
new CrudCacheServiceBase<CompanyDto, Company>(
|
|
|
|
|
s.GetService<IAsbCloudDbContext>(),
|
|
|
|
|
dbSet => dbSet.Include(c=>c.CompanyType)));
|
2022-01-12 13:33:16 +05:00
|
|
|
|
services.AddTransient<ICrudService<CompanyTypeDto>, CrudCacheServiceBase<CompanyTypeDto, CompanyType>>();
|
2022-06-06 15:43:47 +05:00
|
|
|
|
services.AddTransient<ICrudService<ClusterDto>, CrudCacheServiceBase<ClusterDto, Cluster>>(s =>
|
|
|
|
|
new CrudCacheServiceBase<ClusterDto, Cluster>(
|
|
|
|
|
s.GetService<IAsbCloudDbContext>(),
|
|
|
|
|
dbSet => dbSet
|
|
|
|
|
.Include(c => c.Wells)
|
|
|
|
|
.Include(c => c.Deposit))); // может быть включен в сервис ClusterService
|
|
|
|
|
|
2021-12-20 15:17:09 +05:00
|
|
|
|
services.AddTransient<ICrudService<PermissionDto>, CrudCacheServiceBase<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
|
|
|
|
}
|
|
|
|
|
}
|