using System; using System.Collections.Generic; using AsbCloudApp.Data.WellOperation; using AsbCloudApp.Repositories; using AsbCloudApp.Requests.ParserOptions; using AsbCloudApp.Services.Parsers; using AsbCloudDb.Model; using AsbCloudInfrastructure.Services.ExcelServices.Templates.WellOperations; using Microsoft.Extensions.DependencyInjection; namespace AsbCloudInfrastructure.Services.WellOperations.Factories; public class WellOperationParserFactory : IParserFactory { private readonly IDictionary> parsers; public WellOperationParserFactory(IServiceProvider serviceProvider) { var wellOperationRepository = serviceProvider.GetRequiredService(); var categoryRepository = serviceProvider.GetRequiredService(); parsers = new Dictionary> { { WellOperation.IdOperationTypeFact, () => new WellOperationParser(wellOperationRepository, categoryRepository) }, { WellOperation.IdOperationTypePlan, () => new WellOperationParser(wellOperationRepository, categoryRepository) } }; } public IParserService CreateParser(int id) where TOptions : IParserOptionsRequest { var parser = parsers[id].Invoke(); return parser as IParserService ?? throw new ArgumentNullException(nameof(id), "Не удалось распознать файл"); } }