2025-11-01 15:29:12 +10:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2026-04-14 16:27:27 +10:00
|
|
|
|
using PARR.Core;
|
2025-11-01 15:29:12 +10:00
|
|
|
|
using PARR.DAL;
|
2026-04-14 16:27:27 +10:00
|
|
|
|
using PARR.Infrastructure;
|
2026-06-11 15:09:46 +10:00
|
|
|
|
using PARR.TemplateMatcher.Services.GroupedSync;
|
2025-12-23 18:27:31 +10:00
|
|
|
|
using PARR.TemplateMatcher.Services.Implementations;
|
2025-11-01 15:29:12 +10:00
|
|
|
|
using PARR.TemplateMatcher.Services.Interfaces;
|
2026-06-11 15:09:46 +10:00
|
|
|
|
using PARR.TemplateMatcher.Services.SimpleSync;
|
2025-11-01 15:29:12 +10:00
|
|
|
|
using PARR.TemplateMatcher.Settings;
|
|
|
|
|
|
|
|
|
|
|
|
namespace PARR.TemplateMatcher
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class TemplateMatcherInstaller
|
|
|
|
|
|
{
|
|
|
|
|
|
public static void InstallTemplateMatcherSerivces(this IServiceCollection services, IConfiguration configuration)
|
|
|
|
|
|
{
|
2026-04-30 10:35:31 +10:00
|
|
|
|
services.AddDalServices(configuration);
|
2026-04-14 16:27:27 +10:00
|
|
|
|
services.AddCoreServices(configuration);
|
|
|
|
|
|
services.AddInfrastructureServices(configuration);
|
2025-11-01 15:29:12 +10:00
|
|
|
|
|
|
|
|
|
|
var mqSettings = new MqSettings();
|
|
|
|
|
|
configuration.GetSection(nameof(MqSettings)).Bind(mqSettings);
|
|
|
|
|
|
services.AddSingleton(mqSettings);
|
|
|
|
|
|
|
2026-02-20 15:57:51 +10:00
|
|
|
|
var templateSettings = new TemplateSettings();
|
|
|
|
|
|
configuration.GetSection(nameof(TemplateSettings)).Bind(templateSettings);
|
|
|
|
|
|
services.AddSingleton(templateSettings);
|
|
|
|
|
|
|
2026-05-20 17:59:06 +10:00
|
|
|
|
// === 1. Singleton: Долгоживущие сервисы и обработчики очередей ===
|
|
|
|
|
|
services.AddSingleton<IMqTemplateMatcher, MqTemplateMatcher>();
|
|
|
|
|
|
|
|
|
|
|
|
// === 2. Scoped: Бизнес-логика и работа с БД (DbContext) ===
|
|
|
|
|
|
// Создаются заново для каждого сообщения из очереди (внутри CreateAsyncScope)
|
2026-06-11 15:09:46 +10:00
|
|
|
|
services.AddScoped<ITemplateMatcher, Services.Implementations.TemplateMatcher>();
|
|
|
|
|
|
|
|
|
|
|
|
// Simple pipeline: Read-этапы
|
|
|
|
|
|
services.AddScoped<ISimpleSyncStage, Services.Implementations.SimpleSync.LoadJobStage>(); //1
|
|
|
|
|
|
services.AddScoped<ISimpleSyncStage, Services.Implementations.SimpleSync.FilterUnitsStage>(); //2
|
|
|
|
|
|
services.AddScoped<ISimpleSyncStage, Services.Implementations.SimpleSync.AnalyzeChangesStage>(); //3
|
|
|
|
|
|
|
|
|
|
|
|
// Simple pipeline: Write-этапы
|
|
|
|
|
|
services.AddScoped<ISimpleSyncWriteStage, Services.Implementations.SimpleSync.AllocateTemplatesStage>(); //4
|
|
|
|
|
|
services.AddScoped<ISimpleSyncWriteStage, Services.Implementations.SimpleSync.UpdateNamesStage>(); //5
|
|
|
|
|
|
services.AddScoped<ISimpleSyncWriteStage, Services.Implementations.SimpleSync.DeactivateTemplatesStage>(); //6
|
|
|
|
|
|
|
2026-05-20 17:59:06 +10:00
|
|
|
|
services.AddScoped<ITemplateSynchronizer, SimpleTemplateSynchronizer>();
|
2026-06-11 15:09:46 +10:00
|
|
|
|
|
|
|
|
|
|
// Grouped pipeline: Read-этапы
|
|
|
|
|
|
services.AddScoped<IGroupedSyncStage, Services.Implementations.GroupedSync.LoadJobGroupStage>(); //1
|
|
|
|
|
|
services.AddScoped<IGroupedSyncStage, Services.Implementations.GroupedSync.FilterUnitsStage>(); //2
|
|
|
|
|
|
services.AddScoped<IGroupedSyncStage, Services.Implementations.GroupedSync.GroupFilterStage>(); //3
|
|
|
|
|
|
services.AddScoped<IGroupedSyncStage, Services.Implementations.GroupedSync.ResolveConflictsStage>(); //4
|
|
|
|
|
|
services.AddScoped<IGroupedSyncStage, Services.Implementations.GroupedSync.BuildGroupsStage>(); //5
|
|
|
|
|
|
|
|
|
|
|
|
// Grouped pipeline: Write-этапы
|
|
|
|
|
|
services.AddScoped<IGroupedSyncWriteStage, Services.Implementations.GroupedSync.ProcessGroupsStage>(); //6
|
|
|
|
|
|
services.AddScoped<IGroupedSyncWriteStage, Services.Implementations.GroupedSync.DeactivateTemplatesStage>();//7
|
|
|
|
|
|
|
2026-05-20 17:59:06 +10:00
|
|
|
|
services.AddScoped<ITemplateSynchronizer, GroupedTemplateSynchronizer>();
|
|
|
|
|
|
|
|
|
|
|
|
// Пайплайн аллокации шаблонов
|
|
|
|
|
|
services.AddScoped<ITemplateAllocationService, TemplateAllocationService>();
|
|
|
|
|
|
services.AddScoped<ITemplateReuser, TemplateReuser>();
|
|
|
|
|
|
services.AddScoped<ITemplateDeactivator, TemplateDeactivator>();
|
|
|
|
|
|
|
|
|
|
|
|
// Пайплайн групповых шаблонов
|
|
|
|
|
|
services.AddScoped<IGroupedTemplateUnitFilter, GroupedTemplateUnitFilter>();
|
|
|
|
|
|
services.AddScoped<IUnitInTemplateConflictMapper, UnitInTemplateConflictMapper>();
|
|
|
|
|
|
services.AddScoped<IGroupedTemplateBuilder, GroupedTemplateBuilder>();
|
|
|
|
|
|
services.AddScoped<IGroupedTemplateProcessor, GroupedTemplateProcessor>();
|
|
|
|
|
|
|
|
|
|
|
|
// Валидаторы
|
|
|
|
|
|
services.AddScoped<IJobValidatorService, JobValidatorService>();
|
|
|
|
|
|
services.AddScoped<IJobGroupValidatorService, JobGroupValidatorService>();
|
|
|
|
|
|
|
|
|
|
|
|
// === 3. Transient: Stateless утилиты и инфраструктура ===
|
|
|
|
|
|
// Легковесные сервисы без состояния, создаются по требованию
|
|
|
|
|
|
services.AddTransient<ITemplateMqPublisher, TemplateMqPublisher>();
|
2025-12-26 21:47:53 +10:00
|
|
|
|
services.AddTransient<ITemplateNameNormalizer, TemplateNameNormalizer>();
|
2026-09-10 14:12:47 +10:00
|
|
|
|
|
|
|
|
|
|
//Сервис для неактуальных шаблонов
|
|
|
|
|
|
services.AddScoped<IUnusedTemplatesSyncService, UnusedTemplatesSyncService>();
|
2025-11-01 15:29:12 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static IConfigurationBuilder AddTemplateMatcherConfigurations(this IConfigurationBuilder builder, IServiceCollection services)
|
|
|
|
|
|
{
|
|
|
|
|
|
builder.AddDalConfigurations(services);
|
|
|
|
|
|
|
|
|
|
|
|
return builder;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void AddTemplateMatcherSettings(this IServiceCollection services, IConfiguration configuration)
|
|
|
|
|
|
{
|
|
|
|
|
|
services.AddDallSettings(configuration);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|