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

28 lines
942 B
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using AsbCloudApp.Data;
using AsbCloudApp.Requests.ParserOptions;
using AsbCloudApp.Services;
namespace AsbCloudInfrastructure.Services.Parser;
public class ParserServiceFactory
{
private readonly IDictionary<int, Func<IParserService>> parsers;
public ParserServiceFactory(IDictionary<int, Func<IParserService>> parsers)
{
this.parsers = parsers;
}
public IParserService<TDto, TOptions> Create<TDto, TOptions>(int idParserService)
where TDto : class, IId
where TOptions : IParserOptionsRequest
{
if (!parsers.TryGetValue(idParserService, out var parserService))
throw new ArgumentNullException(nameof(idParserService), "Не правильный идентификатор парсера");
return parserService.Invoke() as IParserService<TDto, TOptions>
?? throw new ArgumentNullException(nameof(idParserService), "Ошибка приведения типа");
}
}