22 lines
644 B
C#
22 lines
644 B
C#
namespace RhSolutions.Services;
|
|
|
|
public class ReaderFactory
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
public ReaderFactory(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
}
|
|
|
|
public IReader GetReader(string readerName)
|
|
{
|
|
return readerName switch
|
|
{
|
|
"Guess" => (IReader)_serviceProvider.GetService(typeof(GuessReader)),
|
|
"Excel" => (IReader)_serviceProvider.GetService(typeof(ExcelReader)),
|
|
_ => throw new ArgumentException($"Незвестный интерфейс {nameof(IReader)}: {readerName}")
|
|
};
|
|
}
|
|
}
|