RhSolutions-AddIn/RhSolutions.AddIn/Services/WriterFactory.cs

22 lines
736 B
C#
Raw Permalink Normal View History

2023-04-17 08:49:26 +03:00
namespace RhSolutions.Services;
public class WriterFactory
{
private readonly IServiceProvider _serviceProvider;
public WriterFactory(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
2023-04-20 09:37:07 +03:00
public IWriter GetWriter(string writerName)
2023-04-17 08:49:26 +03:00
{
2023-05-22 07:31:53 +03:00
return writerName switch
2023-04-17 08:49:26 +03:00
{
2023-06-20 07:25:44 +03:00
"NewPrice" => (IWriter)_serviceProvider.GetService(typeof(NewPriceWriter)),
"CurrentPrice" => (IWriter)_serviceProvider.GetService(typeof(CurrentPriceWriter)),
2023-05-22 07:31:53 +03:00
"Dxf" => (IWriter)_serviceProvider.GetService(typeof(DxfWriter)),
_ => throw new ArgumentException($"Незвестный интерфейс {nameof(IWriter)}: {writerName}")
2023-05-22 07:31:53 +03:00
};
2023-04-17 08:49:26 +03:00
}
2023-06-20 08:14:01 +03:00
}