2026-04-13 16:58:30 +10:00
|
|
|
|
using FluentValidation;
|
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2026-07-13 15:29:48 +10:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
2026-05-19 09:47:35 +10:00
|
|
|
|
using PARR.Core.Common.Helpers;
|
2026-04-14 16:27:27 +10:00
|
|
|
|
using PARR.Core.Common.Implementations;
|
|
|
|
|
|
using PARR.Core.Common.Interfaces;
|
2026-05-04 11:55:07 +10:00
|
|
|
|
using PARR.Core.Services.MatchingStatusService;
|
|
|
|
|
|
using PARR.Core.Services.NextRunServices;
|
|
|
|
|
|
using PARR.Core.Services.NextRunServices.Subservices;
|
2026-07-16 10:12:56 +10:00
|
|
|
|
using PARR.Core.Services.RobotMetrics;
|
2026-06-10 16:48:16 +10:00
|
|
|
|
using PARR.Core.Services.RobotSnapshotServices;
|
2026-07-29 09:50:21 +10:00
|
|
|
|
using PARR.Core.Services.RobotStatusDetails.Implementations;
|
|
|
|
|
|
using PARR.Core.Services.RobotStatusDetails.Interfaces;
|
2026-05-25 16:59:42 +10:00
|
|
|
|
using PARR.Core.Services.RobotTask.Implementations;
|
|
|
|
|
|
using PARR.Core.Services.RobotTask.Interfaces;
|
2026-07-28 14:41:01 +10:00
|
|
|
|
using PARR.Core.Services.RobotTaskDetailsServices.Implementations;
|
|
|
|
|
|
using PARR.Core.Services.RobotTaskDetailsServices.Interfaces;
|
2026-07-23 14:39:55 +10:00
|
|
|
|
using PARR.Core.Services.RobotTaskRobotStatus.Implemetations;
|
|
|
|
|
|
using PARR.Core.Services.RobotTaskRobotStatus.Interfaces;
|
2026-05-04 11:55:07 +10:00
|
|
|
|
using PARR.Core.Services.Shortcodes;
|
2026-05-14 16:31:03 +10:00
|
|
|
|
using PARR.Core.Services.Shortcodes.Handlers;
|
2026-07-13 15:29:48 +10:00
|
|
|
|
using PARR.Core.Services.Snapshots.Implementations;
|
|
|
|
|
|
using PARR.Core.Services.Snapshots.Interfaces;
|
2026-04-30 15:10:35 +10:00
|
|
|
|
using PARR.Core.Services.TaskServices.Handlers;
|
|
|
|
|
|
using PARR.Core.Services.TaskServices.Handlers.Factory;
|
|
|
|
|
|
using PARR.Core.Services.TaskServices.Implementations;
|
|
|
|
|
|
using PARR.Core.Services.TaskServices.Interfaces;
|
|
|
|
|
|
using PARR.Core.Services.TaskServices.Providers;
|
|
|
|
|
|
using PARR.Core.Services.TaskServices.ReconciliationHosted;
|
2026-05-04 11:55:07 +10:00
|
|
|
|
using PARR.Core.Services.UnitFilterService;
|
2026-06-09 17:46:43 +10:00
|
|
|
|
using PARR.Core.Services.UnitFilterService.Matchers;
|
|
|
|
|
|
using PARR.Core.Services.UnitFilterService.Matchers.Interfaces;
|
2026-05-29 17:09:36 +10:00
|
|
|
|
using PARR.Core.Services.UnitService.Implementations;
|
|
|
|
|
|
using PARR.Core.Services.UnitService.Interfaces;
|
2026-04-21 16:54:39 +10:00
|
|
|
|
using PARR.Core.Services.Workload.Implementations;
|
|
|
|
|
|
using PARR.Core.Services.Workload.Interfaces;
|
2026-04-22 16:13:23 +10:00
|
|
|
|
using PARR.Domain.Enums;
|
2026-04-14 16:42:15 +10:00
|
|
|
|
using PARR.Domain.Settings;
|
2026-04-13 16:58:30 +10:00
|
|
|
|
|
|
|
|
|
|
namespace PARR.Core
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class DependencyInjection
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Регистрация Core (BLL) сервисов
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="services"></param>
|
|
|
|
|
|
/// <param name="configuration"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static IServiceCollection AddCoreServices(this IServiceCollection services, IConfiguration configuration)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Регим профили AutoMapper
|
|
|
|
|
|
services.AddBllMapping();
|
|
|
|
|
|
|
|
|
|
|
|
// Регим все валидаторы в Core
|
|
|
|
|
|
services.AddValidatorsFromAssembly(typeof(DependencyInjection).Assembly, includeInternalTypes: true);
|
|
|
|
|
|
|
2026-04-14 16:42:15 +10:00
|
|
|
|
// Регим настройки
|
|
|
|
|
|
services.RegisterSettings(configuration);
|
|
|
|
|
|
|
|
|
|
|
|
// --- Регистрируем сревисы Core ---
|
2026-04-14 16:27:27 +10:00
|
|
|
|
|
|
|
|
|
|
#region Common
|
|
|
|
|
|
|
|
|
|
|
|
services.AddTransient<ITransformService, TransformService>();
|
|
|
|
|
|
|
2026-05-19 09:47:35 +10:00
|
|
|
|
#region Helpers
|
|
|
|
|
|
|
|
|
|
|
|
services.AddScoped<JobGroupUnitFilterSynchronizeHelper>();
|
|
|
|
|
|
services.AddScoped<JobGroupCloneHelper>();
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2026-04-14 16:27:27 +10:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2026-04-21 16:54:39 +10:00
|
|
|
|
#region Task
|
|
|
|
|
|
|
2026-04-22 16:13:23 +10:00
|
|
|
|
// ---------> Регистрируем в AddTaskManagement <---------
|
2026-04-21 16:54:39 +10:00
|
|
|
|
|
2026-04-22 16:13:23 +10:00
|
|
|
|
//// Регистрация хендлеров (нужно регистировать каждый отдельно)
|
|
|
|
|
|
//services.AddScoped<WorkloadReportHandler>();
|
|
|
|
|
|
//services.AddScoped<BaseTaskHandler>(sp => sp.GetRequiredService<WorkloadReportHandler>());// регим для фабрики
|
|
|
|
|
|
//// Еще хэндлеры...
|
2026-04-14 16:27:27 +10:00
|
|
|
|
|
2026-04-22 16:13:23 +10:00
|
|
|
|
//// Фабрика хэндлеров
|
|
|
|
|
|
//services.AddScoped<ITaskHandlerFactory, TaskHandlerFactory>();
|
|
|
|
|
|
|
|
|
|
|
|
//services.AddScoped<ITaskManagementService, TaskManagementService>();
|
|
|
|
|
|
|
|
|
|
|
|
//// Провайдер настроек MQ
|
|
|
|
|
|
//services.AddSingleton<ITaskMqSettingsProvider, TaskMqSettingsProvider>();
|
2026-04-21 16:54:39 +10:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2026-05-14 16:31:03 +10:00
|
|
|
|
#region Shortсodes
|
|
|
|
|
|
|
|
|
|
|
|
services.AddScoped<IShortcodeHandler, ConstantsShortcodeHandler>();
|
|
|
|
|
|
services.AddScoped<IShortcodeHandler, StandardShortcodeHandler>();
|
|
|
|
|
|
services.AddScoped<IShortcodeHandler, IndexShortcodeHandler>();
|
|
|
|
|
|
services.AddScoped<IShortcodeHandler, GroupedFieldShortcodeHandler>();
|
|
|
|
|
|
services.AddScoped<IShortcodeHandler, MaxShortcodeHandler>();
|
2026-05-15 15:11:04 +10:00
|
|
|
|
services.AddScoped<IShortcodeHandler, RelationshipUnitShortcodeHandler>();
|
2026-05-14 16:31:03 +10:00
|
|
|
|
services.AddScoped<IShortcodeHandler, LettersShortcodeHandler>();
|
|
|
|
|
|
services.AddScoped<IShortcodeHandler, RelationshipsShortcodeHandler>();
|
|
|
|
|
|
services.AddScoped<IShortcodeHandler, FieldShortcodeHandler>();
|
2026-05-25 16:35:37 +10:00
|
|
|
|
services.AddScoped<IShortcodeHandler, TagShortcodeHandler>();
|
|
|
|
|
|
services.AddScoped<IShortcodeHandler, RelatedUnitTagShortcodeHandler>();
|
2026-05-14 16:31:03 +10:00
|
|
|
|
|
|
|
|
|
|
services.AddScoped<IShortcodesService, ShortcodesService>();
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2026-05-25 16:59:42 +10:00
|
|
|
|
#region Services
|
|
|
|
|
|
|
2026-05-04 11:55:07 +10:00
|
|
|
|
services.AddTransient<IMatchingStatusService, MatchingStatusService>();
|
|
|
|
|
|
|
2026-05-25 16:59:42 +10:00
|
|
|
|
services.AddScoped<IRobotTaskService, RobotTaskService>();
|
2026-06-10 16:48:16 +10:00
|
|
|
|
services.AddScoped<IRobotSnapshotService, RobotSnapshotService>();
|
2026-07-23 14:39:55 +10:00
|
|
|
|
services.AddScoped<IRobotTaskRobotStatusService, RobotTaskRobotStatusService>();
|
2026-07-28 14:41:01 +10:00
|
|
|
|
services.AddScoped<IRobotTaskDetailsService, RobotTaskDetailsService>();
|
2026-07-29 09:50:21 +10:00
|
|
|
|
services.AddScoped<IRobotStatusDetailsService, RobotStatusDetailsService>();
|
2026-05-04 11:55:07 +10:00
|
|
|
|
|
2026-05-29 17:09:36 +10:00
|
|
|
|
services.AddScoped<IUnitService, UnitService>();
|
|
|
|
|
|
services.AddScoped<UnitCacheService>();
|
|
|
|
|
|
|
2026-07-16 10:12:56 +10:00
|
|
|
|
services.AddScoped<IRobotMetricsService, RobotMetricsService>();
|
|
|
|
|
|
|
2026-05-25 16:59:42 +10:00
|
|
|
|
//services.AddScoped<IUserService, UserService>();
|
2026-05-04 11:55:07 +10:00
|
|
|
|
|
2026-05-05 14:52:17 +10:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2026-07-13 15:29:48 +10:00
|
|
|
|
#region Сервисы сбора снапшотов
|
|
|
|
|
|
|
|
|
|
|
|
services.TryAddSingleton<ISnapshotSettings, DefaultSnapshotSettings>();
|
|
|
|
|
|
|
|
|
|
|
|
services.AddScoped<ISnapshotProvider, RobotConfigurationSnapshotService>();
|
|
|
|
|
|
services.AddScoped<ISnapshotProvider, RobotSnapshotService>();
|
|
|
|
|
|
// тут другие сервисы, реализующие ISnapshotProvider
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2026-05-05 14:52:17 +10:00
|
|
|
|
#region Workload
|
|
|
|
|
|
|
|
|
|
|
|
services.AddScoped<WorkloadCacheService>();
|
2026-05-06 17:00:08 +10:00
|
|
|
|
services.AddScoped<IWorkloadService, WorkloadService>();
|
2026-05-04 11:55:07 +10:00
|
|
|
|
|
2026-05-19 09:45:38 +10:00
|
|
|
|
services.AddSingleton<IWorkloadIntervalService, WorkloadIntervalService>();
|
|
|
|
|
|
|
2026-05-04 11:55:07 +10:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region NextRun
|
|
|
|
|
|
|
|
|
|
|
|
services.AddTransient<IEsppScheduleTransformService, EsppScheduleTransformService>();
|
|
|
|
|
|
services.AddTransient<ITemplateDistributor, TemplateDistributor>();
|
|
|
|
|
|
services.AddTransient<INextRunService, NextRunService>();
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region UnitFilterService
|
|
|
|
|
|
|
2026-06-09 17:46:43 +10:00
|
|
|
|
services.AddScoped<IUnitFieldMatcher, UnitFieldMatcher>();
|
|
|
|
|
|
services.AddScoped<IUnitRelationshipMatcher, UnitRelationshipMatcher>();
|
|
|
|
|
|
services.AddScoped<IUmbrellaFilter, UmbrellaFilter>();
|
|
|
|
|
|
services.AddScoped<IUnitNameResolver, UnitNameResolver>();
|
|
|
|
|
|
services.AddScoped<IUnitFilterResultLoader, UnitFilterResultLoader>();
|
|
|
|
|
|
services.AddScoped<IUnitFilterService, UnitFilterService>();
|
2026-04-13 16:58:30 +10:00
|
|
|
|
|
2026-04-14 16:27:27 +10:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2026-04-21 16:54:39 +10:00
|
|
|
|
#region IMessageConsumer services
|
|
|
|
|
|
|
|
|
|
|
|
services.AddSingleton<IWorkloadCacheBuilderService, WorkloadCacheBuilderService>();
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2026-04-13 16:58:30 +10:00
|
|
|
|
return services;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-22 16:13:23 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Регистрация сервисов по управлению задчами (Task)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="services"></param>
|
|
|
|
|
|
/// <param name="mqSettingsFactory">Настройки MQ для всех TaskTypeEnum</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
|
|
|
|
public static IServiceCollection AddTaskManagement(this IServiceCollection services, Func<IServiceProvider, TaskTypeEnum, IMqSettings> mqSettingsFactory)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (mqSettingsFactory == null)
|
|
|
|
|
|
throw new ArgumentNullException(nameof(mqSettingsFactory), "Ты забыл зарегистрировать настройки MQ для Task! Бестолочь! :)");
|
|
|
|
|
|
|
|
|
|
|
|
// Регистрация хендлеров (нужно регистировать каждый отдельно)
|
|
|
|
|
|
services.AddScoped<WorkloadReportHandler>();
|
|
|
|
|
|
services.AddScoped<BaseTaskHandler>(sp => sp.GetRequiredService<WorkloadReportHandler>());// регим для фабрики хэндлеров
|
|
|
|
|
|
// Еще хэндлеры...
|
|
|
|
|
|
|
|
|
|
|
|
// Фабрика хэндлеров
|
|
|
|
|
|
services.AddScoped<ITaskHandlerFactory, TaskHandlerFactory>();
|
|
|
|
|
|
|
|
|
|
|
|
services.AddScoped<ITaskManagementService, TaskManagementService>();
|
|
|
|
|
|
|
|
|
|
|
|
// Провайдер настроек MQ
|
|
|
|
|
|
services.AddTransient<Func<TaskTypeEnum, IMqSettings>>(sp => (taskType) => mqSettingsFactory(sp, taskType)); // регим фабрику настроек для ITaskMqSettingsProvider
|
|
|
|
|
|
services.AddSingleton<ITaskMqSettingsProvider, TaskMqSettingsProvider>();
|
|
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-13 16:58:30 +10:00
|
|
|
|
|
2026-04-23 16:08:16 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Подключение сервисов для TaskReconciliation
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="services"></param>
|
|
|
|
|
|
/// <param name="configureSettings"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static IServiceCollection AddTaskReconciliation(this IServiceCollection services, IReconciliationSettings reconciliationSettings)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (reconciliationSettings == null)
|
|
|
|
|
|
throw new ArgumentNullException(nameof(reconciliationSettings));
|
|
|
|
|
|
|
|
|
|
|
|
// Настройки
|
|
|
|
|
|
services.AddSingleton(reconciliationSettings);
|
|
|
|
|
|
|
|
|
|
|
|
// Сервис
|
|
|
|
|
|
services.AddScoped<ITaskReconciliationService, TaskReconciliationService>();
|
|
|
|
|
|
|
|
|
|
|
|
// Воркер
|
|
|
|
|
|
services.AddHostedService<ReconciliationHostedService>();
|
|
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-04-13 16:58:30 +10:00
|
|
|
|
private static IServiceCollection AddBllMapping(this IServiceCollection services)
|
|
|
|
|
|
{
|
|
|
|
|
|
// AutoMapper
|
|
|
|
|
|
services.AddAutoMapper(cfg =>
|
|
|
|
|
|
{
|
|
|
|
|
|
// регим все в Core
|
|
|
|
|
|
cfg.AddMaps(typeof(DependencyInjection).Assembly);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-14 16:42:15 +10:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Регистрация настроек
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="services"></param>
|
|
|
|
|
|
/// <param name="configuration"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private static IServiceCollection RegisterSettings(this IServiceCollection services, IConfiguration configuration)
|
|
|
|
|
|
{
|
|
|
|
|
|
var groupedShortcodesCacheSettings = new GroupedShortcodesCacheSettings();
|
|
|
|
|
|
configuration.GetSection(nameof(GroupedShortcodesCacheSettings)).Bind(groupedShortcodesCacheSettings);
|
|
|
|
|
|
services.AddSingleton(groupedShortcodesCacheSettings);
|
|
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-13 16:58:30 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|