2021-04-02 17:28:07 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using AsbCloudInfrastructure.Services;
|
2021-10-01 15:44:56 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.Analysis;
|
2021-04-07 18:01:56 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.Cache;
|
2021-10-09 20:16:22 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.WellOperationService;
|
2022-01-10 16:00:09 +05:00
|
|
|
|
using AsbCloudInfrastructure.Validators;
|
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-12-27 17:35:49 +05:00
|
|
|
|
using FluentValidation;
|
|
|
|
|
using FluentValidation.AspNetCore;
|
2022-02-12 11:28:16 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.DrillingProgram;
|
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-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();
|
|
|
|
|
|
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-02-17 15:37:27 +05:00
|
|
|
|
services.AddHostedService<TelemetryAnalyticsBackgroundService>();// replace by BackgroundWorkerService
|
2021-05-19 14:41:27 +05:00
|
|
|
|
|
2021-04-07 18:01:56 +05:00
|
|
|
|
services.AddSingleton(new CacheDb());
|
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>();
|
2021-12-20 15:17:09 +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-08-13 15:57:22 +05:00
|
|
|
|
services.AddTransient<ITelemetryAnalyticsService, TelemetryAnalyticsService>();
|
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>();
|
|
|
|
|
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>();
|
2021-08-24 10:59:10 +05:00
|
|
|
|
|
2021-09-10 11:28:57 +05:00
|
|
|
|
// admin crud services:
|
2022-01-12 13:33:16 +05:00
|
|
|
|
services.AddTransient<ICrudService<TelemetryDto>, CrudServiceBase<TelemetryDto, Telemetry>>(); // может быть включен в сервис TelemetryService
|
2021-12-03 15:03:33 +05:00
|
|
|
|
services.AddTransient<ICrudService<DrillParamsDto>, DrillParamsService>();
|
2022-01-12 13:33:16 +05:00
|
|
|
|
services.AddTransient<ICrudService<DepositDto>, CrudCacheServiceBase<DepositDto, Deposit>>();
|
|
|
|
|
services.AddTransient<ICrudService<CompanyDto>, CrudCacheServiceBase<CompanyDto, Company>>();
|
|
|
|
|
services.AddTransient<ICrudService<CompanyTypeDto>, CrudCacheServiceBase<CompanyTypeDto, CompanyType>>();
|
|
|
|
|
services.AddTransient<ICrudService<ClusterDto>, CrudCacheServiceBase<ClusterDto, Cluster>>(); // может быть включен в сервис 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-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
|
|
|
|
}
|
|
|
|
|
}
|