DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/Parser/ParserServiceFactory.cs
2024-02-14 12:13:43 +03:00

28 lines
942 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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), "Ошибка приведения типа");
}
}