Files
parr_api/PARR.TemplateMatcher/TemplateMatcherInstaller.cs

72 lines
3.5 KiB
C#
Raw Normal View History

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>();
2025-12-26 21:47:53 +10:00
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);
}
}
}