DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/ParserServiceFactory.cs

30 lines
1.0 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using AsbCloudApp.Data;
using AsbCloudApp.Requests.Import;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.Trajectory.Parser;
namespace AsbCloudInfrastructure.Services;
public class ParserServiceFactory
{
public const int IdTrajectoryFactManualParserService = 1;
public const int IdTrajectoryPlanParserService = 2;
private readonly IDictionary<int, Func<IParserService>> parsers = new Dictionary<int, Func<IParserService>>
{
{ IdTrajectoryPlanParserService, () => new TrajectoryPlanParserService() },
{ IdTrajectoryFactManualParserService, () => new TrajectoryFactManualParserService() }
};
public IParserService<TDto, TOptions> Create<TDto, TOptions>(int idImportService)
where TDto : class, IId
where TOptions : ParserOptionsRequestBase
{
var parser = parsers[idImportService].Invoke();
return parser as IParserService<TDto, TOptions>
?? throw new ArgumentNullException(nameof(idImportService), "Не удалось распознать файл");
}
}