forked from ddrilling/AsbCloudServer
102 lines
5.3 KiB
C#
102 lines
5.3 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Services;
|
|
using AsbCloudDb.Model;
|
|
using AsbCloudInfrastructure.Services;
|
|
using AsbCloudInfrastructure.Services.Analysis;
|
|
using AsbCloudInfrastructure.Services.Cache;
|
|
using AsbCloudInfrastructure.Services.WellOperationService;
|
|
using AsbCloudInfrastructure.Validators;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System;
|
|
using FluentValidation;
|
|
using FluentValidation.AspNetCore;
|
|
|
|
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 IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
services.AddDbContext<AsbCloudDbContext>(options =>
|
|
options.UseNpgsql(configuration.GetConnectionString("DefaultConnection")));
|
|
|
|
services.AddFluentValidation();
|
|
|
|
services.AddScoped<IAsbCloudDbContext>(provider => provider.GetService<AsbCloudDbContext>());
|
|
services.AddScoped<IFileShareService, GoogleDriveService>();
|
|
|
|
services.AddHostedService<ReportsBackgroundService>();
|
|
services.AddHostedService<TelemetryAnalyticsBackgroundService>();
|
|
|
|
services.AddSingleton(new CacheDb());
|
|
services.AddSingleton<ITelemetryTracker, TelemetryTracker>();
|
|
services.AddSingleton<IReportsBackgroundQueue, ReportsBackgroundQueue>();
|
|
services.AddSingleton<IRequerstTrackerService, RequerstTrackerService>();
|
|
|
|
services.AddTransient<IAuthService, AuthService>();
|
|
services.AddTransient<IClusterService, ClusterService>();
|
|
services.AddTransient<IDrillFlowChartService, DrillFlowChartService>();
|
|
services.AddTransient<IDrillingProgramService, DrillingProgramService>();
|
|
services.AddTransient<IDrillParamsService, DrillParamsService>();
|
|
services.AddTransient<IEventService, EventService>();
|
|
services.AddTransient<IFileService, FileService>();
|
|
services.AddTransient<IMeasureService, MeasureService>();
|
|
services.AddTransient<IMessageService, MessageService>();
|
|
services.AddTransient<IOperationsStatService, OperationsStatService>();
|
|
services.AddTransient<IReportService, ReportService>();
|
|
services.AddTransient<ISetpointsService, SetpointsService>();
|
|
services.AddTransient<ITelemetryAnalyticsService, TelemetryAnalyticsService>();
|
|
services.AddTransient<ITelemetryService, TelemetryService>();
|
|
services.AddTransient<ITelemetryUserService, TelemetryUserService>();
|
|
services.AddTransient<ITimeZoneService, TimeZoneService>();
|
|
services.AddTransient<IUserService, UserService>();
|
|
services.AddTransient<IUserRoleService, UserRoleService>();
|
|
services.AddTransient<IWellService, WellService>();
|
|
services.AddTransient<IWellCompositeService, WellCompositeService>();
|
|
services.AddTransient<IWellOperationImportService, WellOperationImportService>();
|
|
services.AddTransient<IWellOperationService, WellOperationService>();
|
|
|
|
// admin crud services:
|
|
services.AddTransient<ICrudService<TelemetryDto>, CrudServiceBase<TelemetryDto, Telemetry>>();
|
|
services.AddTransient<ICrudService<DrillParamsDto>, DrillParamsService>();
|
|
services.AddTransient<ICrudService<DepositDto>, CrudServiceBase<DepositDto, Deposit>>();
|
|
services.AddTransient<ICrudService<CompanyDto>, CrudServiceBase<CompanyDto, Company>>();
|
|
services.AddTransient<ICrudService<ClusterDto>, CrudServiceBase<ClusterDto, Cluster>>();
|
|
services.AddTransient<ICrudService<PermissionDto>, CrudCacheServiceBase<PermissionDto, Permission>>();
|
|
|
|
// TelemetryData services
|
|
services.AddTransient<ITelemetryDataService<TelemetryDataSaubDto>, TelemetryDataSaubService>();
|
|
services.AddTransient<ITelemetryDataService<TelemetryDataSpinDto>, TelemetryDataSpinService>();
|
|
|
|
// Validation rules
|
|
services.AddTransient<IValidator<AuthDto>, AuthDtoValidator>();
|
|
|
|
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.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)));
|
|
|
|
}
|
|
}
|