/
afanasevn
/
MaxSystems
Обзор
Документация
Войти
/
afanasevn
/
MaxSystems
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/MaxSystems.Infrastructure/DependencyInjection.cs
58 строк
3 KB
IBS\NAfanasev
Production tests added
30 июн 2026, 13:52
30 июн 2026, 13:52
919fb54
Код
Авторство
О чём код?
using MaxSystems.Application.Abstractions; using MaxSystems.Infrastructure.Auth; using MaxSystems.Infrastructure.Data; using MaxSystems.Infrastructure.Integration; using MaxSystems.Infrastructure.Services; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; namespace MaxSystems.Infrastructure; /// <summary>Регистрация сервисов Infrastructure и миграции БД.</summary> public static class DependencyInjection { /// <summary>Регистрирует DbContext, JWT и доменные сервисы приложения.</summary> public static IServiceCollection AddInfrastructure( this IServiceCollection services, string connectionString) { services.AddDbContext<AppDbContext>( options => options.UseNpgsql(connectionString), contextLifetime: ServiceLifetime.Scoped, optionsLifetime: ServiceLifetime.Singleton); services.AddSingleton<JwtTokenService>(); services.AddScoped<IAuthService, AuthService>(); services.AddScoped<IReportService, ReportService>(); services.AddScoped<IEquipmentService, EquipmentService>(); services.AddScoped<IUserService, UserService>(); services.AddScoped<IMaintenanceService, MaintenanceService>(); services.AddScoped<IWorkService, WorkService>(); services.AddScoped<IWarehouseService, WarehouseService>(); services.AddScoped<IImportService, ImportService>(); services.AddScoped<IAuditService, AuditService>(); services.AddScoped<IIntegrationDeliveryJournalService, IntegrationDeliveryJournalService>(); services.AddScoped<IIntegrationDeliveryQueryService, IntegrationDeliveryQueryService>(); services.AddScoped<IntegrationEventReplayPayloadBuilder>(); return services; } /// <summary>Применяет EF-миграции без seed (Worker).</summary> public static async Task MigrateDatabaseAsync(this IServiceProvider services) { using var scope = services.CreateScope(); var db = scope.ServiceProvider.GetRequiredService<AppDbContext>(); await db.Database.MigrateAsync(); } /// <summary>Применяет EF-миграции и seed для API при старте.</summary> public static async Task MigrateAndSeedAsync(this IServiceProvider services) { using var scope = services.CreateScope(); var db = scope.ServiceProvider.GetRequiredService<AppDbContext>(); await db.Database.MigrateAsync(); await Seeding.DatabaseSeeder.SeedAsync(db); await Seeding.DatabaseSeeder.EnsurePasswordsAsync(db); } }