22 lines
736 B
C#
22 lines
736 B
C#
namespace RhSolutions.Services;
|
|
|
|
public class WriterFactory
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
public WriterFactory(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
}
|
|
|
|
public IWriter GetWriter(string writerName)
|
|
{
|
|
return writerName switch
|
|
{
|
|
"NewPrice" => (IWriter)_serviceProvider.GetService(typeof(NewPriceWriter)),
|
|
"CurrentPrice" => (IWriter)_serviceProvider.GetService(typeof(CurrentPriceWriter)),
|
|
"Dxf" => (IWriter)_serviceProvider.GetService(typeof(DxfWriter)),
|
|
_ => throw new ArgumentException($"Незвестный интерфейс {nameof(IWriter)}: {writerName}")
|
|
};
|
|
}
|
|
} |