DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/WellOperations/Factories/WellOperationParserFactory.cs

43 lines
1.6 KiB
C#
Raw Normal View History

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<int, WellOperationDto>
{
private readonly IDictionary<int, Func<IParserService>> parsers;
public WellOperationParserFactory(IServiceProvider serviceProvider)
{
var wellOperationRepository = serviceProvider.GetRequiredService<IWellOperationRepository>();
var categoryRepository = serviceProvider.GetRequiredService<IWellOperationCategoryRepository>();
parsers = new Dictionary<int, Func<IParserService>>
{
{
WellOperation.IdOperationTypeFact,
() => new WellOperationParser<WellOperationFactTemplate>(wellOperationRepository, categoryRepository)
},
{
WellOperation.IdOperationTypePlan,
() => new WellOperationParser<WellOperationPlanTemplate>(wellOperationRepository, categoryRepository)
}
};
}
public IParserService<WellOperationDto, TOptions> CreateParser<TOptions>(int id)
where TOptions : IParserOptionsRequest
{
var parser = parsers[id].Invoke();
return parser as IParserService<WellOperationDto, TOptions>
?? throw new ArgumentNullException(nameof(id), "Не удалось распознать файл");
}
}