aboutsummaryrefslogtreecommitdiff
path: root/RhSolutions.AddIn/Services/ReaderFactory.cs
blob: b7483cebc93d396ec3f69c0abba3282fac34839c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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}")
        };
    }
}