2024-01-29 15:03:53 +05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using AsbCloudApp.Data;
|
2024-01-31 17:20:54 +05:00
|
|
|
|
using AsbCloudApp.Requests.ParserOptions;
|
2024-02-01 16:35:29 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
2024-01-29 15:03:53 +05:00
|
|
|
|
|
2024-02-13 16:05:16 +05:00
|
|
|
|
namespace AsbCloudInfrastructure.Services.Parser;
|
2024-01-29 15:03:53 +05:00
|
|
|
|
|
2024-02-14 14:13:43 +05:00
|
|
|
|
public class ParserServiceFactory
|
2024-01-29 15:03:53 +05:00
|
|
|
|
{
|
2024-02-01 16:35:29 +05:00
|
|
|
|
private readonly IDictionary<int, Func<IParserService>> parsers;
|
2024-01-29 15:03:53 +05:00
|
|
|
|
|
2024-02-14 14:13:43 +05:00
|
|
|
|
public ParserServiceFactory(IDictionary<int, Func<IParserService>> parsers)
|
2024-01-29 15:03:53 +05:00
|
|
|
|
{
|
2024-02-14 14:13:43 +05:00
|
|
|
|
this.parsers = parsers;
|
2024-01-31 17:20:54 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-01 16:35:29 +05:00
|
|
|
|
public IParserService<TDto, TOptions> Create<TDto, TOptions>(int idParserService)
|
2024-01-31 17:20:54 +05:00
|
|
|
|
where TDto : class, IId
|
|
|
|
|
where TOptions : IParserOptionsRequest
|
|
|
|
|
{
|
|
|
|
|
if (!parsers.TryGetValue(idParserService, out var parserService))
|
2024-02-01 16:35:29 +05:00
|
|
|
|
throw new ArgumentNullException(nameof(idParserService), "Не правильный идентификатор парсера");
|
2024-01-31 17:20:54 +05:00
|
|
|
|
|
2024-02-01 16:35:29 +05:00
|
|
|
|
return parserService.Invoke() as IParserService<TDto, TOptions>
|
2024-01-31 17:20:54 +05:00
|
|
|
|
?? throw new ArgumentNullException(nameof(idParserService), "Ошибка приведения типа");
|
2024-01-29 15:03:53 +05:00
|
|
|
|
}
|
|
|
|
|
}
|