RhSolutions-AddIn/RhSolutions.AddIn/Services/ReaderFactory.cs

22 lines
644 B
C#
Raw Permalink Normal View History

2023-05-22 07:39:48 +03:00
namespace RhSolutions.Services;
public class ReaderFactory
{
private readonly IServiceProvider _serviceProvider;
public ReaderFactory(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
public IReader GetReader(string readerName)
{
return readerName switch
{
2023-05-23 07:07:16 +03:00
"Guess" => (IReader)_serviceProvider.GetService(typeof(GuessReader)),
2023-05-22 07:39:48 +03:00
"Excel" => (IReader)_serviceProvider.GetService(typeof(ExcelReader)),
_ => throw new ArgumentException($"Незвестный интерфейс {nameof(IReader)}: {readerName}")
2023-05-22 07:39:48 +03:00
};
}
}