Внедрить фабрики объектов вместо прямого new
Создание сервисов с порт-интерфейсом перенесено в IXxxFactory: шифр секретов, хранилище лимитов, ИИ-классификатор, ИИ-инструменты, файловое хранилище (Local/MinIO). Регистраторы и DiscoveryWorkerService больше не создают реализации напрямую. Добавлен тест FileStorageFactory.
This commit is contained in:
@@ -5,8 +5,12 @@ using Deal.Infrastructure.Integrations.Options;
|
||||
using Deal.Infrastructure.Integrations.Services;
|
||||
using Deal.Infrastructure.Integrations.Sources;
|
||||
using Deal.Infrastructure.Persistence;
|
||||
using Deal.Infrastructure.Persistence.Abstractions;
|
||||
using Deal.Infrastructure.Persistence.Repositories;
|
||||
using Deal.Infrastructure.Persistence.Services;
|
||||
using Deal.Infrastructure.Security;
|
||||
using Deal.Infrastructure.Security.Abstractions;
|
||||
using Deal.Infrastructure.Security.Services;
|
||||
using Deal.Infrastructure.Services;
|
||||
using Deal.Infrastructure.Tenancy;
|
||||
using Deal.Modules.Cards.Application.Abstractions;
|
||||
@@ -20,7 +24,6 @@ using Deal.Modules.Tenants.Application.Abstractions;
|
||||
using Deal.Modules.Tenants.Application.Models;
|
||||
using Deal.SharedKernel.Tenants.Abstractions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Deal.Infrastructure;
|
||||
|
||||
@@ -46,9 +49,9 @@ public static class ServiceCollectionExtensions
|
||||
|
||||
services.AddScoped<IInviteStore, InviteStore>();
|
||||
|
||||
services.AddScoped<ITenantLimitStore>(provider => new TenantLimitStore(
|
||||
provider.GetRequiredService<DealDbContext>(),
|
||||
tenantLimitDefaults ?? TokenBudgetDefaults.Default));
|
||||
services.AddSingleton(tenantLimitDefaults ?? TokenBudgetDefaults.Default);
|
||||
services.AddScoped<ITenantLimitStoreFactory, TenantLimitStoreFactory>();
|
||||
services.AddScoped<ITenantLimitStore>(provider => provider.GetRequiredService<ITenantLimitStoreFactory>().Create());
|
||||
|
||||
services.AddScoped<IRateLimitCounterStore, RateLimitCounterStore>();
|
||||
|
||||
@@ -117,18 +120,11 @@ public static class ServiceCollectionExtensions
|
||||
services.AddScoped<AiProviderConfigBuilder>();
|
||||
services.AddScoped<GrpcAiClassifier>();
|
||||
services.AddScoped<LocalAiClassifier>();
|
||||
services.AddScoped<IAiClassifier>(provider => new BudgetedAiClassifier(
|
||||
provider.GetRequiredService<GrpcAiClassifier>(),
|
||||
provider.GetRequiredService<LocalAiClassifier>(),
|
||||
provider.GetRequiredService<ITenantLimitStore>(),
|
||||
provider.GetRequiredService<ITenantContext>(),
|
||||
provider.GetRequiredService<ILogger<BudgetedAiClassifier>>()));
|
||||
services.AddScoped<IAiClassifierFactory, AiClassifierFactory>();
|
||||
services.AddScoped<IAiClassifier>(provider => provider.GetRequiredService<IAiClassifierFactory>().Create());
|
||||
services.AddScoped<GrpcAiTools>();
|
||||
services.AddScoped<IAiTools>(provider => new BudgetedAiTools(
|
||||
provider.GetRequiredService<GrpcAiTools>(),
|
||||
provider.GetRequiredService<ITenantLimitStore>(),
|
||||
provider.GetRequiredService<ITenantContext>(),
|
||||
provider.GetRequiredService<ILogger<BudgetedAiTools>>()));
|
||||
services.AddScoped<IAiToolsFactory, AiToolsFactory>();
|
||||
services.AddScoped<IAiTools>(provider => provider.GetRequiredService<IAiToolsFactory>().Create());
|
||||
}
|
||||
|
||||
if (telegramOptions.UseLocal)
|
||||
@@ -152,8 +148,9 @@ public static class ServiceCollectionExtensions
|
||||
public static IServiceCollection AddDealSecurity(this IServiceCollection services, string contentRootPath)
|
||||
{
|
||||
EncryptionKeyProvider keyProvider = new(contentRootPath);
|
||||
byte[] key = keyProvider.GetKey();
|
||||
services.AddSingleton<ISecretCipher>(new AesGcmSecretCipher(key));
|
||||
services.AddSingleton(keyProvider);
|
||||
services.AddSingleton<ISecretCipherFactory, SecretCipherFactory>();
|
||||
services.AddSingleton<ISecretCipher>(provider => provider.GetRequiredService<ISecretCipherFactory>().Create());
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user