Files
parr_api/PARR.TemplateMatcher/TemplateMatcherInstaller.cs
Mikhail Kuznetsov 513e5f869a fix(templateMatcher): Исправление ошибок в именах шаблонов и рефакторинг синхронизации
- Устранена ошибка, когда при переиспользовании шаблона для шорткодов передавался ЭК "КОМПЛЕКСЫ-[ЗО]" вместо целевого ЭК шаблона.
- Проведен небольшой рефакторинг общих процессов синхронизации различных типов групп работ.
2026-05-20 17:59:06 +10:00

72 lines
3.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PARR.Core;
using PARR.DAL;
using PARR.Infrastructure;
using PARR.TemplateMatcher.Services.Implementations;
using PARR.TemplateMatcher.Services.Implemetaions;
using PARR.TemplateMatcher.Services.Interfaces;
using PARR.TemplateMatcher.Settings;
namespace PARR.TemplateMatcher
{
public static class TemplateMatcherInstaller
{
public static void InstallTemplateMatcherSerivces(this IServiceCollection services, IConfiguration configuration)
{
services.AddDalServices(configuration);
services.AddCoreServices(configuration);
services.AddInfrastructureServices(configuration);
var mqSettings = new MqSettings();
configuration.GetSection(nameof(MqSettings)).Bind(mqSettings);
services.AddSingleton(mqSettings);
var templateSettings = new TemplateSettings();
configuration.GetSection(nameof(TemplateSettings)).Bind(templateSettings);
services.AddSingleton(templateSettings);
// === 1. Singleton: Долгоживущие сервисы и обработчики очередей ===
services.AddSingleton<IMqTemplateMatcher, MqTemplateMatcher>();
// === 2. Scoped: Бизнес-логика и работа с БД (DbContext) ===
// Создаются заново для каждого сообщения из очереди (внутри CreateAsyncScope)
services.AddScoped<ITemplateMatcher, TemplateMatcher>();
services.AddScoped<ITemplateSynchronizer, SimpleTemplateSynchronizer>();
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>();
services.AddTransient<ITemplateNameNormalizer, TemplateNameNormalizer>();
}
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);
}
}
}