using System; using System.Collections.Generic; using AsbCloudApp.Repositories; using AsbCloudApp.Requests.ExportOptions; using AsbCloudApp.Services; using AsbCloudApp.Services.Export; using AsbCloudDb.Model; using AsbCloudInfrastructure.Services.ExcelServices.Templates.WellOperations; using Microsoft.Extensions.DependencyInjection; namespace AsbCloudInfrastructure.Services.WellOperations.Factories; public class WellOperationExportServiceFactory : IExportServiceFactory { private readonly IDictionary> exportServices; public WellOperationExportServiceFactory(IServiceProvider serviceProvider) { var wellOperationRepository = serviceProvider.GetRequiredService(); var wellService = serviceProvider.GetRequiredService(); exportServices = new Dictionary> { { WellOperation.IdOperationTypeFact, () => new WellOperationExport(wellOperationRepository, wellService) }, { WellOperation.IdOperationTypePlan, () => new WellOperationExport(wellOperationRepository, wellService) } }; } public IExportService CreateExportService(int id) where TOptions : IExportOptionsRequest { var parser = exportServices[id].Invoke(); return parser as IExportService ?? throw new ArgumentNullException(nameof(id), "Не удалось экспортировать файл"); } }